CanCraft() public abstract méthode

public abstract CanCraft ( Mobile from, BaseTool tool, Type itemType ) : int
from Mobile
tool BaseTool
itemType Type
Résultat int
Exemple #1
0
        public static void CraftItem(CraftItem item, CraftSystem system, Mobile from, BaseTool tool)
        {
            int          num     = system.CanCraft(from, tool, item.ItemType);
            CraftContext context = system.GetContext(from);

            if (context == null)
            {
                return;
            }

            if (num > 0)
            {
                context.Making = null;

                from.SendGump(new CraftGump(from, system, tool, num));
            }
            else
            {
                context.Making = item;

                Type type = null;

                CraftSubResCol res      = (item.UseSubRes2 ? system.CraftSubRes2 : system.CraftSubRes);
                int            resIndex = (item.UseSubRes2 ? context.LastResourceIndex2 : context.LastResourceIndex);

                if (resIndex >= 0 && resIndex < res.Count)
                {
                    type = res.GetAt(resIndex).ItemType;
                }

                system.CreateItem(from, item.ItemType, type, tool, item);
            }
        }
            protected override void OnTarget(Mobile from, object targeted)
            {
                int num = m_CraftSystem.CanCraft(from, m_Tool, null);

                if (num > 0)
                {
                    from.SendGump(new CraftGump(from, m_CraftSystem, m_Tool, num));
                    return;
                }

                if (targeted is BaseArmor helm && helm is IFortifiable)
                {
                    if (!helm.IsChildOf(from.Backpack))
                    {
                        from.SendFailureMessage("The helm has to be in your backpack.");
                        return;
                    }

                    if (helm.HitPoints != helm.MaxHitPoints)
                    {
                        from.SendFailureMessage("You must repair that first.");
                        return;
                    }

                    if (!from.ShilCheckSkill(m_CraftSystem.MainSkill, -1, 250))
                    {
                        from.SendFailureMessage("You fail and ruin both, the hat and the helm.");
                        m_Hat.Delete();
                        helm.Delete();
                    }

                    m_Hat.Fortify(helm);

                    m_Hat.OnSingleClick(m_From);
                }
Exemple #3
0
        public void CraftItem(CraftItem item)
        {
            int num = m_CraftSystem.CanCraft(m_From, m_Tool, item.ItemType);

            if (num > 0)
            {
                m_From.SendGump(new CraftGump(m_From, m_CraftSystem, m_Tool, num));
            }
            else
            {
                Type type = null;

                CraftContext context = m_CraftSystem.GetContext(m_From);

                if (context != null)
                {
                    CraftSubResCol res      = (item.UseSubRes2 ? m_CraftSystem.CraftSubRes2 : m_CraftSystem.CraftSubRes);
                    int            resIndex = (item.UseSubRes2 ? context.LastResourceIndex2 : context.LastResourceIndex);

                    if (resIndex >= 0 && resIndex < res.Count)
                    {
                        type = res.GetAt(resIndex).ItemType;
                    }
                }

                m_CraftSystem.CreateItem(m_From, item.ItemType, type, m_Tool, item);
            }
        }
Exemple #4
0
        public void CraftItem(CraftItem item)
        {
            object num = m_CraftSystem.CanCraft(m_From, m_Tool, item.ItemType);

            if ((num is int && (int)num > 0) || (num is string && !string.IsNullOrWhiteSpace((string)num)))
            {
                m_From.SendGump(new CraftGump(m_From, m_CraftSystem, m_Tool, num));
            }
            else
            {
                Type type = null;

                CraftContext context = m_CraftSystem.GetContext(m_From);

                if (context != null)
                {
                    CraftSubResCol res      = (item.UseSubRes2 ? m_CraftSystem.CraftSubRes2 : m_CraftSystem.CraftSubRes);
                    int            resIndex = (item.UseSubRes2 ? context.LastResourceIndex2 : context.LastResourceIndex);

                    if (resIndex >= 0 && resIndex < res.Count)
                    {
                        type = res.GetAt(resIndex).ItemType;
                    }
                }

                m_CraftSystem.CreateItem(m_From, item.ItemType, type, m_Tool, item);
            }
        }
Exemple #5
0
            protected override void OnTarget(Mobile from, object targeted)
            {
                int num = m_CraftSystem.CanCraft(from, m_Tool, null);

                if (num > 0)
                {
                    from.SendGump(new CraftGump(from, m_CraftSystem, m_Tool, num));
                }
                else
                {
                    bool success       = false;
                    bool isStoreBought = false;
                    bool lackMining    = false;

                    Process(m_CraftSystem, from, targeted, true, out success, out isStoreBought, out lackMining);

                    if (lackMining)
                    {
                        from.SendGump(new CraftGump(from, m_CraftSystem, m_Tool, 1044269));                             // You have no idea how to work this metal.
                        return;
                    }

                    if (success)
                    {
                        // You melt the item down into ingots.
                        from.SendGump(new CraftGump(from, m_CraftSystem, m_Tool, isStoreBought ? 500418 : 1044270));
                    }
                    else
                    {
                        // You can't melt that down into ingots.
                        from.SendGump(new CraftGump(from, m_CraftSystem, m_Tool, 1044272));
                    }
                }
            }
Exemple #6
0
            protected override void OnTarget(Mobile from, object targeted)
            {
                int num = m_CraftSystem.CanCraft(from, m_Tool, null);

                if (num > 0)
                {
                    if (num == 1044267)
                    {
                        bool anvil, forge;

                        DefBlacksmithy.CheckAnvilAndForge(from, 2, out anvil, out forge);

                        if (!anvil)
                        {
                            num = 1044266;                             // You must be near an anvil
                        }
                        else if (!forge)
                        {
                            num = 1044265;                             // You must be near a forge.
                        }
                    }

                    from.SendGump(new CraftGump(from, m_CraftSystem, m_Tool, num));
                }
                else
                {
                    SmeltResult result        = SmeltResult.Invalid;
                    bool        isStoreBought = false;
                    int         message;

                    if (targeted is BaseArmor)
                    {
                        result        = Resmelt(from, (BaseArmor)targeted, ((BaseArmor)targeted).Resource);
                        isStoreBought = !((BaseArmor)targeted).PlayerConstructed;
                    }
                    else if (targeted is BaseWeapon)
                    {
                        result        = Resmelt(from, (BaseWeapon)targeted, ((BaseWeapon)targeted).Resource);
                        isStoreBought = !((BaseWeapon)targeted).PlayerConstructed;
                    }
                    else if (targeted is DragonBardingDeed)
                    {
                        result        = Resmelt(from, (DragonBardingDeed)targeted, ((DragonBardingDeed)targeted).Resource);
                        isStoreBought = false;
                    }

                    switch (result)
                    {
                    default:
                    case SmeltResult.Invalid: message = 1044272; break;                             // You can't melt that down into ingots.

                    case SmeltResult.NoSkill: message = 1044269; break;                             // You have no idea how to work this metal.

                    case SmeltResult.Success: message = isStoreBought ? 500418 : 1044270; break;    // You melt the item down into ingots.
                    }

                    from.SendGump(new CraftGump(from, m_CraftSystem, m_Tool, message));
                }
            }
Exemple #7
0
        public override void OnResponse(NetState sender, RelayInfo info)
        {
            switch (info.ButtonID)
            {
            case 0:     // Back Button
            {
                CraftGump craftGump = new CraftGump(m_From, m_CraftSystem, m_Tool, null);
                m_From.SendGump(craftGump);
                break;
            }

            case 1:     // Make Button
            {
                if (m_CraftItem.TryCraft != null)
                {
                    m_CraftItem.TryCraft(m_From, m_CraftItem, m_Tool);
                    return;
                }

                int num = m_CraftSystem.CanCraft(m_From, m_Tool, m_CraftItem.ItemType);

                if (num > 0)
                {
                    m_From.SendGump(new CraftGump(m_From, m_CraftSystem, m_Tool, num));
                }
                else
                {
                    Type type = null;

                    CraftContext context = m_CraftSystem.GetContext(m_From);

                    if (context != null)
                    {
                        CraftSubResCol res      = (m_CraftItem.UseSubRes2 ? m_CraftSystem.CraftSubRes2 : m_CraftSystem.CraftSubRes);
                        int            resIndex = (m_CraftItem.UseSubRes2 ? context.LastResourceIndex2 : context.LastResourceIndex);

                        if (resIndex > -1)
                        {
                            type = res.GetAt(resIndex).ItemType;
                        }
                    }

                    m_CraftSystem.CreateItem(m_From, m_CraftItem.ItemType, type, m_Tool, m_CraftItem);
                }
                break;
            }

            case 2:                                   //Make Number
                m_From.Prompt = new MakeNumberCraftPrompt(m_From, m_CraftSystem, m_CraftItem, m_Tool);
                m_From.SendLocalizedMessage(1112576); //Please type the amount you wish to create(1 - 100): <Escape to cancel>
                break;

            case 3:     //Make Max
                AutoCraftTimer.EndTimer(m_From);
                new AutoCraftTimer(m_From, m_CraftSystem, m_CraftItem, m_Tool, 9999, TimeSpan.FromSeconds(m_CraftSystem.Delay * m_CraftSystem.MaxCraftEffect + 1.0), TimeSpan.FromSeconds(m_CraftSystem.Delay * m_CraftSystem.MaxCraftEffect + 1.0));
                break;
            }
        }
Exemple #8
0
	    public static void Do( Mobile from, CraftSystem craftSystem, BaseTool tool )
		{
			int num = craftSystem.CanCraft( from, tool, null );

            if (num > 0 && num != 1044267)
                from.SendGump(new CraftGump(from, craftSystem, tool, num));
			else
			{
				from.Target = new InternalTarget( craftSystem, tool );
				from.SendLocalizedMessage( 1044273 ); // Target an item to recycle.
			}
		}
Exemple #9
0
            protected override void OnTarget(Mobile from, object targeted)
            {
                int num = m_CraftSystem.CanCraft(from, m_Tool, null);

                if (num > 0)
                {
                    from.SendGump(new CraftGump(from, m_CraftSystem, m_Tool, num));
                }
                else
                {
                    bool success       = false;
                    bool isStoreBought = false;
                    bool lackMining    = false;

                    if (targeted is BaseArmor)
                    {
                        success       = Resmelt(from, (BaseArmor)targeted, ((BaseArmor)targeted).Resource);
                        isStoreBought = !((BaseArmor)targeted).PlayerConstructed;
                        lackMining    = !(CheckResourceSkill(((BaseArmor)targeted).Resource, from.Skills[SkillName.Mining].Value));
                    }
                    else if (targeted is BaseWeapon)
                    {
                        success       = Resmelt(from, (BaseWeapon)targeted, ((BaseWeapon)targeted).Resource);
                        isStoreBought = !((BaseWeapon)targeted).PlayerConstructed;
                        lackMining    = !(CheckResourceSkill(((BaseWeapon)targeted).Resource, from.Skills[SkillName.Mining].Value));
                    }
                    else if (targeted is DragonBardingDeed)
                    {
                        success       = Resmelt(from, (DragonBardingDeed)targeted, ((DragonBardingDeed)targeted).Resource);
                        isStoreBought = false;
                        lackMining    = false;
                    }

                    if (lackMining)
                    {
                        from.SendGump(new CraftGump(from, m_CraftSystem, m_Tool, 1044269));                             // You have no idea how to work this metal.

                        return;
                    }

                    if (success)
                    {
                        // You melt the item down into ingots.
                        from.SendGump(new CraftGump(from, m_CraftSystem, m_Tool, isStoreBought ? 500418 : 1044270));
                    }
                    else
                    {
                        // You can't melt that down into ingots.
                        from.SendGump(new CraftGump(from, m_CraftSystem, m_Tool, 1044272));
                    }
                }
            }
Exemple #10
0
        public static void Do( Mobile from, CraftSystem craftSystem, BaseTool tool )
        {
            string num = craftSystem.CanCraft( from, tool, null );

            if ( num != "" )
            {
                from.SendGump( new CraftGump( from, craftSystem, tool, num ) );
            }
            else
            {
                from.Target = new InternalTarget( craftSystem, tool );
                from.SendAsciiMessage( "Target an item to recycle." );
            }
        }
Exemple #11
0
        public static void Do(Mobile from, CraftSystem craftSystem, BaseTool tool)
        {
            string num = craftSystem.CanCraft(from, tool, null);

            if (num != "")
            {
                from.SendGump(new CraftGump(from, craftSystem, tool, num));
            }
            else
            {
                from.Target = new InternalTarget(craftSystem, tool);
                from.SendAsciiMessage("Target an item to recycle.");
            }
        }
Exemple #12
0
        public static void Do(Mobile from, CraftSystem craftSystem, BaseTool tool)
        {
            object num = craftSystem.CanCraft(from, tool, null);

            if ((num is int && (int)num > 0 && (int)num != 1044267) || (num is string && !string.IsNullOrWhiteSpace((string)num)))
            {
                from.SendGump(new CraftGump(from, craftSystem, tool, num));
            }
            else
            {
                from.Target = new InternalTarget(craftSystem, tool);
                from.SendLocalizedMessage(1044273);                   // Target an item to recycle.
            }
        }
        public static void Do(Mobile from, CraftSystem craftSystem, BaseTool tool)
        {
            int num = craftSystem.CanCraft(from, tool, null);

            if (num > 0)
            {
                from.SendGump(new CraftGump(from, craftSystem, tool, num));
            }
            else
            {
                from.Target = new InternalTarget1(from, craftSystem, tool);
                from.SendSuccessMessage("Select a hat to fortify.");
            }
        }
Exemple #14
0
        public static void Do(Mobile from, CraftSystem craftSystem, BaseTool tool)
        {
            int num = craftSystem.CanCraft(from, tool, null);

            if (num > 0 && num != 1044267)
            {
                from.SendGump(new CraftGump(from, craftSystem, tool, num));
            }
            else
            {
                from.Target = new InternalTarget(craftSystem, tool);
                from.SendLocalizedMessage(1044273);                   // Target an item to recycle.
            }
        }
Exemple #15
0
        public override void OnResponse(NetState sender, RelayInfo info)
        {
            //Back
            if (info.ButtonID == 0)
            {
                CraftGump craftGump = new CraftGump(m_From, m_CraftSystem, m_Tool, null);
                m_From.SendGump(craftGump);
            }

            //Guide
            else if (info.ButtonID == 1000)
            {
                string url = "http://www.uoancorp.com";
                sender.Mobile.LaunchBrowser(url);

                m_From.SendGump(new CraftGumpItem(m_From, m_CraftSystem, m_CraftItem, m_Tool));
                return;
            }

            //Make
            else
            {
                int num = m_CraftSystem.CanCraft(m_From, m_Tool, m_CraftItem.ItemType);

                if (num > 0)
                {
                    m_From.SendGump(new CraftGump(m_From, m_CraftSystem, m_Tool, num));
                }

                else
                {
                    Type type = null;

                    CraftContext context = m_CraftSystem.GetContext(m_From);

                    if (context != null)
                    {
                        CraftSubResCol res      = (m_CraftItem.UseSubRes2 ? m_CraftSystem.CraftSubRes2 : m_CraftSystem.CraftSubRes);
                        int            resIndex = (m_CraftItem.UseSubRes2 ? context.LastResourceIndex2 : context.LastResourceIndex);

                        if (resIndex > -1)
                        {
                            type = res.GetAt(resIndex).ItemType;
                        }
                    }

                    m_CraftSystem.CreateItem(m_From, m_CraftItem.ItemType, type, m_Tool, m_CraftItem);
                }
            }
        }
        public static void RecyclePrompt(Mobile from, CraftSystem craftSystem, BaseTool tool)
        {
            int num = craftSystem.CanCraft(from, tool, null);

            if (num > 0 && num != 1044267)
            {
                from.SendGump(new CraftGump(from, craftSystem, tool, num));
            }

            else
            {
                CraftContext context = craftSystem.GetContext(from);

                if (context == null)
                {
                    return;
                }

                from.Target = new InternalTarget(craftSystem, tool);

                switch (context.RecycleOption)
                {
                case CraftRecycleOption.RecycleSingle:
                    from.SendMessage("Target an individual item to recycle.");
                    break;

                case CraftRecycleOption.RecycleRegularByType:
                    from.SendMessage("Target the type of item you wish to recycle. All regular items of that type found in your pack will be recycled.");
                    break;

                case CraftRecycleOption.RecycleExceptionalByType:
                    from.SendMessage("Target the type of item you wish to recycle. All exceptional-quality items of that type found in your pack will be recycled.");
                    break;

                case CraftRecycleOption.RecycleMagicalByType:
                    from.SendMessage("Target the type of item you wish to recycle. All magical items of that type found in your pack will be recycled.");
                    break;

                case CraftRecycleOption.RecycleAnyByType:
                    from.SendMessage("Target the type of item you wish to recycle. Any items of that type found in your pack will be recycled.");
                    break;

                case CraftRecycleOption.RecycleEverything:
                    from.SendMessage(1256, "Warning! You are about to recycle ALL craftable items of ANY type made with Ingots, Boards, Leather, or Cloth inside your backpack and containers within. Target yourself to proceed.");
                    break;
                }
            }
        }
Exemple #17
0
        public static void PublicOnTarget( Mobile from, object targeted, CraftSystem m_CraftSystem, BaseTool m_Tool )
        {
            int num = m_CraftSystem.CanCraft( from, m_Tool, null );

            if ( num > 0 )
            {
                from.SendGump( new CraftGump( from, m_CraftSystem, m_Tool, num ) );
            }
            else
            {
                bool success = false;
                bool isStoreBought = false;

                if ( targeted is BaseArmor )
                {
                    success = PublicResmelt( from, (BaseArmor)targeted, ((BaseArmor)targeted).Resource, m_CraftSystem );
                    isStoreBought = false;
                }
                else if ( targeted is BaseWeapon )
                {
                    success = PublicResmelt( from, (BaseWeapon)targeted, ((BaseWeapon)targeted).Resource, m_CraftSystem );
                    isStoreBought = false;
                }
                else if ( targeted is DragonBardingDeed )
                {
                    success = PublicResmelt( from, (DragonBardingDeed)targeted, ((DragonBardingDeed)targeted).Resource, m_CraftSystem );
                    isStoreBought = false;
                }
                else if ( targeted is BaseJewel )
                {
                    success = SmeltJewelry( from, (BaseJewel)targeted );
                    isStoreBought = false;
                }

                if ( success )
                    from.SendGump( new CraftGump( from, m_CraftSystem, m_Tool, isStoreBought ? 500418 : 1044270 ) ); // You melt the item down into ingots.
                else
                    from.SendGump( new CraftGump( from, m_CraftSystem, m_Tool, 1044272 ) ); // You can't melt that down into ingots.
            }
        }
            protected override void OnTarget(Mobile from, object targeted)
            {
                int num = m_CraftSystem.CanCraft(from, m_Tool, null);

                if (num > 0)
                {
                    from.SendGump(new CraftGump(from, m_CraftSystem, m_Tool, num));
                }
                else
                {
                    bool success       = false;
                    bool isStoreBought = false;

                    if (targeted is BaseArmor)
                    {
                        success       = Resmelt(from, (BaseArmor)targeted, ((BaseArmor)targeted).Resource);
                        isStoreBought = !((BaseArmor)targeted).PlayerConstructed;
                    }
                    else if (targeted is BaseWeapon)
                    {
                        success       = Resmelt(from, (BaseWeapon)targeted, ((BaseWeapon)targeted).Resource);
                        isStoreBought = !((BaseWeapon)targeted).PlayerConstructed;
                    }
                    else if (targeted is DragonBardingDeed)
                    {
                        success       = Resmelt(from, (DragonBardingDeed)targeted, ((DragonBardingDeed)targeted).Resource);
                        isStoreBought = false;
                    }

                    if (success)
                    {
                        from.SendGump(new CraftGump(from, m_CraftSystem, m_Tool, isStoreBought ? 500418 : 1044270)); // You melt the item down into ingots.
                        Do(from, m_CraftSystem, m_Tool);
                    }
                    else
                    {
                        from.SendGump(new CraftGump(from, m_CraftSystem, m_Tool, 1044272));                             // You can't melt that down into ingots.
                    }
                }
            }
            protected override void OnTarget(Mobile from, object targeted)
            {
                int num = m_CraftSystem.CanCraft(from, m_Tool, null);

                if (num > 0)
                {
                    from.SendGump(new CraftGump(from, m_CraftSystem, m_Tool, num));
                    return;
                }

                if (targeted is BaseHat hat)
                {
                    if (!hat.IsChildOf(from.Backpack))
                    {
                        from.SendFailureMessage("The hat has to be in your backpack.");
                        return;
                    }

                    if (hat.Fortified == ItemFortificationType.Fortified)
                    {
                        from.SendFailureMessage("That is fortified already!");
                        return;
                    }

                    if (hat.HitPoints != hat.MaxHitPoints)
                    {
                        from.SendFailureMessage("You must repair that first.");
                        return;
                    }

                    from.Target = new InternalTarget2(m_From, m_CraftSystem, m_Tool, hat);
                    from.SendSuccessMessage("Select the helm to fortify this hat with.");
                }
                else
                {
                    from.SendFailureMessage("That's not a hat.");
                }
            }
Exemple #20
0
            protected override void OnTarget(Mobile from, object targeted)
            {
                int num = m_CraftSystem.CanCraft(from, m_Tool, null);

                if (num > 0)
                {
                    from.SendGump(new CraftGump(from, m_CraftSystem, m_Tool, num));
                    return;
                }

                RecycleResult result = RecycleResult.Invalid;

                string message;

                Item item = targeted as Item;

                if (item == null)
                {
                    return;
                }

                else
                {
                    result = Recycle(from, item);
                }

                switch (result)
                {
                default:
                case RecycleResult.Invalid: message = "That cannot be recycled."; break;

                case RecycleResult.NoSkill: message = "You do not know how to recycle this material."; break;

                case RecycleResult.Success: message = "You recycle the item."; break;
                }

                from.SendGump(new CraftGump(from, m_CraftSystem, m_Tool, message));
            }
        public override void OnResponse(NetState sender, RelayInfo info)
        {
            // Back Button
            if (info.ButtonID == 0)
            {
                CraftGump craftGump = new CraftGump(m_From, m_CraftSystem, m_Tool, null);
                m_From.SendGump(craftGump);
            }
            else             // Make Button
            {
                int num = m_CraftSystem.CanCraft(m_From, m_Tool, m_CraftItem.ItemType);

                if (num > 0)
                {
                    m_From.SendGump(new CraftGump(m_From, m_CraftSystem, m_Tool, num));
                }
                else
                {
                    Type type = null;

                    CraftContext context = m_CraftSystem.GetContext(m_From);

                    if (context != null)
                    {
                        CraftSubResCol res      = (m_CraftItem.UseSubRes2 ? m_CraftSystem.CraftSubRes2 : m_CraftSystem.CraftSubRes);
                        int            resIndex = (m_CraftItem.UseSubRes2 ? context.LastResourceIndex2 : context.LastResourceIndex);

                        if (resIndex > -1)
                        {
                            type = res.GetAt(resIndex).ItemType;
                        }
                    }

                    m_CraftSystem.CreateItem(m_From, m_CraftItem.ItemType, type, m_Tool, m_CraftItem);
                }
            }
        }
Exemple #22
0
        public static void Do(Mobile from, CraftSystem craftSystem, BaseTool tool)
        {
            int num = craftSystem.CanCraft(from, tool, null);

            if (num > 0 && num != 1044267)
            {
                from.SendGump(new CraftGump(from, craftSystem, tool, num));
            }

            else
            {
                CraftContext context = craftSystem.GetContext(from);

                if (context == null)
                {
                    return;
                }

                from.Target = new InternalTarget(craftSystem, tool);

                switch (context.RecycleOption)
                {
                case CraftRecycleOption.RecycleItem:
                    from.SendMessage("Target an item to recycle.");
                    break;

                case CraftRecycleOption.RecycleAllNonExceptional:
                    from.SendMessage("Target the type of item you wish to recycle. All non-exceptional items of that type found in your pack will be processed.");
                    break;

                case CraftRecycleOption.RecycleAll:
                    from.SendMessage("Target the type of item you wish to recycle. All items of that type found in your pack will be processed.");
                    break;
                }
            }
        }
Exemple #23
0
        public void Craft(Mobile from, CraftSystem craftSystem, Type typeRes, BaseTool tool)
        {
            if (from.BeginAction(typeof(CraftSystem)))
            {
                if (RequiredExpansion == Expansion.None || (from.NetState != null && from.NetState.SupportsExpansion(RequiredExpansion)))
                {
                    bool   allRequiredSkills = true;
                    double chance            = GetSuccessChance(from, typeRes, craftSystem, false, ref allRequiredSkills);

                    if (allRequiredSkills && chance >= 0.0)
                    {
                        if (this.Recipe == null || !(from is PlayerMobile) || ((PlayerMobile)from).HasRecipe(this.Recipe))
                        {
                            int badCraft = craftSystem.CanCraft(from, tool, m_Type);

                            if (badCraft <= 0)
                            {
                                int    resHue    = 0;
                                int    maxAmount = 0;
                                object message   = null;

                                if (ConsumeRes(from, typeRes, craftSystem, ref resHue, ref maxAmount, ConsumeType.None, ref message))
                                {
                                    message = null;

                                    if (ConsumeAttributes(from, ref message, false))
                                    {
                                        CraftContext context = craftSystem.GetContext(from);

                                        if (context != null)
                                        {
                                            context.OnMade(this);
                                        }

                                        int iMin    = craftSystem.MinCraftEffect;
                                        int iMax    = (craftSystem.MaxCraftEffect - iMin) + 1;
                                        int iRandom = Utility.Random(iMax);
                                        iRandom += iMin + 1;
                                        new InternalTimer(from, craftSystem, this, typeRes, tool, iRandom).Start();
                                    }
                                    else
                                    {
                                        from.EndAction(typeof(CraftSystem));
                                        from.SendGump(new CraftGump(from, craftSystem, tool, message));
                                    }
                                }
                                else
                                {
                                    from.EndAction(typeof(CraftSystem));
                                    from.SendGump(new CraftGump(from, craftSystem, tool, message));
                                }
                            }
                            else
                            {
                                from.EndAction(typeof(CraftSystem));
                                from.SendGump(new CraftGump(from, craftSystem, tool, badCraft));
                            }
                        }
                        else
                        {
                            from.EndAction(typeof(CraftSystem));
                            from.SendGump(new CraftGump(from, craftSystem, tool, 1072847)); // You must learn that recipe from a scroll.
                        }
                    }
                    else
                    {
                        from.EndAction(typeof(CraftSystem));
                        from.SendGump(new CraftGump(from, craftSystem, tool, 1044153)); // You don't have the required skills to attempt this item.
                    }
                }
                else
                {
                    from.EndAction(typeof(CraftSystem));
                    from.SendGump(new CraftGump(from, craftSystem, tool, RequiredExpansionMessage(RequiredExpansion))); //The {0} expansion is required to attempt this item.
                }
            }
            else
            {
                from.SendLocalizedMessage(500119); // You must wait to perform another action
            }
        }
		public void CompleteCraft( int quality, bool makersMark, Mobile from, CraftSystem craftSystem, Type typeRes, BaseTool tool, CustomCraft customCraft )
		{
			int badCraft = craftSystem.CanCraft( from, tool, m_Type );

			if ( badCraft > 0 )
			{
				if ( tool != null && !tool.Deleted && tool.UsesRemaining > 0 )
					from.SendGump( new CraftGump( from, craftSystem, tool, badCraft ) );
				else
					from.SendLocalizedMessage( badCraft );

				return;
			}

			int checkResHue = 0, checkMaxAmount = 0;
			object checkMessage = null;

			// Not enough resource to craft it
			if ( !ConsumeRes( from, typeRes, craftSystem, ref checkResHue, ref checkMaxAmount, ConsumeType.None, ref checkMessage ) )
			{
				if ( tool != null && !tool.Deleted && tool.UsesRemaining > 0 )
					from.SendGump( new CraftGump( from, craftSystem, tool, checkMessage ) );
				else if ( checkMessage is int && (int)checkMessage > 0 )
					from.SendLocalizedMessage( (int)checkMessage );
				else if ( checkMessage is string )
					from.SendMessage( (string)checkMessage );

				return;
			}
			else if ( !ConsumeAttributes( from, ref checkMessage, false ) )
			{
				if ( tool != null && !tool.Deleted && tool.UsesRemaining > 0 )
					from.SendGump( new CraftGump( from, craftSystem, tool, checkMessage ) );
				else if ( checkMessage is int && (int)checkMessage > 0 )
					from.SendLocalizedMessage( (int)checkMessage );
				else if ( checkMessage is string )
					from.SendMessage( (string)checkMessage );

				return;
			}

			bool toolBroken = false;

			int ignored = 1;
			int endquality = 1;

			bool allRequiredSkills = true;

			if ( CheckSkills( from, typeRes, craftSystem, ref ignored, ref allRequiredSkills ) )
			{
				// Resource
				int resHue = 0;
				int maxAmount = 0;

				object message = null;

				// Not enough resource to craft it
				if ( !ConsumeRes( from, typeRes, craftSystem, ref resHue, ref maxAmount, ConsumeType.All, ref message ) )
				{
					if ( tool != null && !tool.Deleted && tool.UsesRemaining > 0 )
						from.SendGump( new CraftGump( from, craftSystem, tool, message ) );
					else if ( message is int && (int)message > 0 )
						from.SendLocalizedMessage( (int)message );
					else if ( message is string )
						from.SendMessage( (string)message );

					return;
				}
				else if ( !ConsumeAttributes( from, ref message, true ) )
				{
					if ( tool != null && !tool.Deleted && tool.UsesRemaining > 0 )
						from.SendGump( new CraftGump( from, craftSystem, tool, message ) );
					else if ( message is int && (int)message > 0 )
						from.SendLocalizedMessage( (int)message );
					else if ( message is string )
						from.SendMessage( (string)message );

					return;
				}

				tool.UsesRemaining--;

				if ( craftSystem is DefBlacksmithy )
				{
					AncientSmithyHammer hammer = from.FindItemOnLayer( Layer.OneHanded ) as AncientSmithyHammer;
					if ( hammer != null && hammer != tool )
					{
						hammer.UsesRemaining--;
						if ( hammer.UsesRemaining < 1 )
							hammer.Delete();
					}
				}

				if ( tool.UsesRemaining < 1 )
					toolBroken = true;

				if ( toolBroken )
					tool.Delete();

				int num = 0;

				Item item;
				if ( customCraft != null )
				{
					item = customCraft.CompleteCraft( out num );
				}
				else if ( typeof( MapItem ).IsAssignableFrom( ItemType ) && from.Map != Map.Trammel && from.Map != Map.Felucca )
				{
					item = new IndecipherableMap();
					from.SendLocalizedMessage( 1070800 ); // The map you create becomes mysteriously indecipherable.
				}
				else
				{
					item = Activator.CreateInstance( ItemType ) as Item;
				}

				if ( item != null )
				{

					if ( item is BaseWeapon )
						((BaseWeapon)item).Identified = true;
					if ( item is BaseArmor )
						((BaseArmor)item).Identified = true;
					if ( item is BaseClothing )
						((BaseClothing)item).Identified = true;
					if ( item is BaseJewel )
						((BaseJewel)item).Identified = true;
				
					//For new boards system
					if ( item is Board )
					{
						Type resourceType = typeRes;
						if ( resourceType == null )
							resourceType = Ressources.GetAt( 0 ).ItemType;

						CraftResource thisResource = CraftResources.GetFromType( resourceType );
						
						switch ( thisResource )
						{
							case CraftResource.Pine: 	item = new PineBoard(); break;
							case CraftResource.Cedar: 	item = new CedarBoard(); break;
							case CraftResource.Cherry: 	item = new CherryBoard(); break;
							case CraftResource.Mahogany: 	item = new MahoganyBoard(); break;
							case CraftResource.Oak: 	item = new OakBoard(); break;
							case CraftResource.Ash: 	item = new AshBoard(); break;
							case CraftResource.Yew: 	item = new YewBoard(); break;
							case CraftResource.Heartwood: 	item = new HeartwoodBoard(); break;
							case CraftResource.Bloodwood: 	item = new BloodwoodBoard(); break;
							case CraftResource.Frostwood: 	item = new FrostwoodBoard(); break;
							default: item = new Board(); break;
						}
						
					}
					//end for new boards system
					
					//For new marble system
					if ( item is Marble )
					{
						Type resourceType = typeRes;
						if ( resourceType == null )
							resourceType = Ressources.GetAt( 0 ).ItemType;

						CraftResource thisResource = CraftResources.GetFromType( resourceType );
						
						switch ( thisResource )
						{
							case CraftResource.DullCopper: 		item = new DullCopperMarble(); break;
							case CraftResource.ShadowIron: 		item = new ShadowIronMarble(); break;
							case CraftResource.Copper: 		item = new CopperMarble(); break;
							case CraftResource.Bronze: 		item = new BronzeMarble(); break;
							case CraftResource.Gold: 		item = new GoldMarble(); break;
							case CraftResource.Agapite: 		item = new AgapiteMarble(); break;
							case CraftResource.Verite: 		item = new VeriteMarble(); break;
							case CraftResource.Valorite: 		item = new ValoriteMarble(); break;
							case CraftResource.Silver: 		item = new SilverMarble(); break;
							case CraftResource.Platinum: 		item = new PlatinumMarble(); break;
							case CraftResource.Mythril: 		item = new MythrilMarble(); break;
							case CraftResource.Obsidian: 		item = new ObsidianMarble(); break;
							case CraftResource.Jade: 		item = new JadeMarble(); break;
							case CraftResource.Moonstone: 		item = new MoonstoneMarble(); break;
							case CraftResource.Sunstone: 		item = new SunstoneMarble(); break;
							case CraftResource.Bloodstone: 		item = new BloodstoneMarble(); break;
							default: item = new Marble(); break;
						}
						
					}
					//end for new marble system

					if( item is ICraftable )
						endquality = ((ICraftable)item).OnCraft( quality, makersMark, from, craftSystem, typeRes, tool, this, resHue );
					else if ( item.Hue == 0 )
						item.Hue = resHue;

					if ( maxAmount > 0 )
					{
						if ( !item.Stackable && item is IUsesRemaining )
							((IUsesRemaining)item).UsesRemaining *= maxAmount;
						else
						item.Amount = maxAmount;
					}

					from.AddToBackpack( item );

					//from.PlaySound( 0x57 );
				}

				if ( num == 0 )
					num = craftSystem.PlayEndingEffect( from, false, true, toolBroken, endquality, makersMark, this );

				bool queryFactionImbue = false;
				int availableSilver = 0;
				FactionItemDefinition def = null;
				Faction faction = null;

				if ( item is IFactionItem )
				{
					def = FactionItemDefinition.Identify( item );

					if ( def != null )
					{
						faction = Faction.Find( from );

						if ( faction != null )
						{
							Town town = Town.FromRegion( from.Region );

							if ( town != null && town.Owner == faction )
							{
								Container pack = from.Backpack;

								if ( pack != null )
								{
									availableSilver = pack.GetAmount( typeof( Silver ) );

									if ( availableSilver >= def.SilverCost )
										queryFactionImbue = Faction.IsNearType( from, def.VendorType, 12 );
								}
							}
						}
					}
				}

				// TODO: Scroll imbuing

				if ( queryFactionImbue )
					from.SendGump( new FactionImbueGump( quality, item, from, craftSystem, tool, num, availableSilver, faction, def ) );
				else if ( tool != null && !tool.Deleted && tool.UsesRemaining > 0 )
					from.SendGump( new CraftGump( from, craftSystem, tool, num ) );
				else if ( num > 0 )
					from.SendLocalizedMessage( num );
			}
			else if ( !allRequiredSkills )
			{
				if ( tool != null && !tool.Deleted && tool.UsesRemaining > 0 )
					from.SendGump( new CraftGump( from, craftSystem, tool, 1044153 ) );
				else
					from.SendLocalizedMessage( 1044153 ); // You don't have the required skills to attempt this item.
			}
			else
			{
				ConsumeType consumeType = ( UseAllRes ? ConsumeType.Half : ConsumeType.All );
				int resHue = 0;
				int maxAmount = 0;

				object message = null;

				// Not enough resource to craft it
				if ( !ConsumeRes( from, typeRes, craftSystem, ref resHue, ref maxAmount, consumeType, ref message, true ) )
				{
					if ( tool != null && !tool.Deleted && tool.UsesRemaining > 0 )
						from.SendGump( new CraftGump( from, craftSystem, tool, message ) );
					else if ( message is int && (int)message > 0 )
						from.SendLocalizedMessage( (int)message );
					else if ( message is string )
						from.SendMessage( (string)message );

					return;
				}

				tool.UsesRemaining--;

				if ( tool.UsesRemaining < 1 )
					toolBroken = true;

				if ( toolBroken )
					tool.Delete();

				// SkillCheck failed.
				int num = craftSystem.PlayEndingEffect( from, true, true, toolBroken, endquality, false, this );

				if ( tool != null && !tool.Deleted && tool.UsesRemaining > 0 )
					from.SendGump( new CraftGump( from, craftSystem, tool, num ) );
				else if ( num > 0 )
					from.SendLocalizedMessage( num );
			}
		}
        public void CompleteCraft(int quality, bool makersMark, Mobile from, CraftSystem craftSystem, Type typeRes, BaseTool tool, CustomCraft customCraft)
        {
            int badCraft = craftSystem.CanCraft(from, tool, m_Type);

            if (badCraft > 0)
            {
                if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
                    from.SendGump(new CraftGump(from, craftSystem, tool, badCraft));
                else
                    from.SendLocalizedMessage(badCraft);

                return;
            }

            int checkResHue = 0, checkMaxAmount = 0;
            object checkMessage = null;

            // Not enough resource to craft it
            if (!ConsumeRes(from, typeRes, craftSystem, ref checkResHue, ref checkMaxAmount, ConsumeType.None, ref checkMessage))
            {
                if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
                    from.SendGump(new CraftGump(from, craftSystem, tool, checkMessage));
                else if (checkMessage is int && (int)checkMessage > 0)
                    from.SendLocalizedMessage((int)checkMessage);
                else if (checkMessage is string)
                    from.SendMessage((string)checkMessage);

                return;
            }
            else if (!ConsumeAttributes(from, ref checkMessage, false))
            {
                if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
                    from.SendGump(new CraftGump(from, craftSystem, tool, checkMessage));
                else if (checkMessage is int && (int)checkMessage > 0)
                    from.SendLocalizedMessage((int)checkMessage);
                else if (checkMessage is string)
                    from.SendMessage((string)checkMessage);

                return;
            }

            bool toolBroken = false;

            int ignored = 1;
            int endquality = 1;

            bool allRequiredSkills = true;

            if (CheckSkills(from, typeRes, craftSystem, ref ignored, ref allRequiredSkills))
            {
                // Resource
                int resHue = 0;
                int maxAmount = 0;

                object message = null;

                // Not enough resource to craft it
                if (!ConsumeRes(from, typeRes, craftSystem, ref resHue, ref maxAmount, ConsumeType.All, ref message))
                {
                    if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
                        from.SendGump(new CraftGump(from, craftSystem, tool, message));
                    else if (message is int && (int)message > 0)
                        from.SendLocalizedMessage((int)message);
                    else if (message is string)
                        from.SendMessage((string)message);

                    return;
                }
                else if (!ConsumeAttributes(from, ref message, true))
                {
                    if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
                        from.SendGump(new CraftGump(from, craftSystem, tool, message));
                    else if (message is int && (int)message > 0)
                        from.SendLocalizedMessage((int)message);
                    else if (message is string)
                        from.SendMessage((string)message);

                    return;
                }

                tool.UsesRemaining--;

                if (craftSystem is DefBlacksmithy)
                {
                    AncientSmithyHammer hammer = from.FindItemOnLayer(Layer.OneHanded) as AncientSmithyHammer;
                    if (hammer != null && hammer != tool)
                    {
                        #region Mondain's Legacy
                        if (hammer is HammerOfHephaestus)
                        {
                            if (hammer.UsesRemaining > 0)
                                hammer.UsesRemaining--;

                            if (hammer.UsesRemaining < 1)
                                from.PlaceInBackpack(hammer);
                        }
                        else
                        {
                            hammer.UsesRemaining--;

                            if (hammer.UsesRemaining < 1)
                                hammer.Delete();
                        }
                        #endregion
                    }
                }

                #region Mondain's Legacy
                if (tool is HammerOfHephaestus)
                {
                    if (tool.UsesRemaining < 1)
                        tool.UsesRemaining = 0;
                }
                else
                {
                    if (tool.UsesRemaining < 1)
                        toolBroken = true;

                    if (toolBroken)
                        tool.Delete();
                }
                #endregion

                int num = 0;

                Item item;
                if (customCraft != null)
                {
                    item = customCraft.CompleteCraft(out num);
                }
                else if (typeof(MapItem).IsAssignableFrom(ItemType) && from.Map != Map.Trammel && from.Map != Map.Felucca)
                {
                    item = new IndecipherableMap();
                    from.SendLocalizedMessage(1070800); // The map you create becomes mysteriously indecipherable.
                }
                else
                {
                    item = Activator.CreateInstance(ItemType) as Item;
                }

                if (item != null)
                {
                    #region Mondain's Legacy
                    if (item is Board)
                    {
                        Type resourceType = typeRes;

                        if (resourceType == null)
                            resourceType = Ressources.GetAt(0).ItemType;

                        CraftResource thisResource = CraftResources.GetFromType(resourceType);

                        switch (thisResource)
                        {
                            case CraftResource.Oak: item = new OakBoard(); break;
                            case CraftResource.Ash: item = new AshBoard(); break;
                            case CraftResource.Yew: item = new YewBoard(); break;
                            case CraftResource.Heartwood: item = new HeartwoodBoard(); break;
                            case CraftResource.Bloodwood: item = new BloodwoodBoard(); break;
                            case CraftResource.Frostwood: item = new FrostwoodBoard(); break;
                            case CraftResource.Pine: item = new PineBoard(); break;
                            case CraftResource.Cedar: item = new CedarBoard(); break;
                            case CraftResource.Cherry: item = new CherryBoard(); break;
                            case CraftResource.Mahogany: item = new MahoganyBoard(); break;
                            default: item = new Board(); break;
                        }
                    }
                    #endregion

                    if (item is ICraftable)
                        endquality = ((ICraftable)item).OnCraft(quality, makersMark, from, craftSystem, typeRes, tool, this, resHue);
                    else if (item.Hue == 0)
                        item.Hue = resHue;

                    if (maxAmount > 0)
                    {
                        if (!item.Stackable && item is IUsesRemaining)
                            ((IUsesRemaining)item).UsesRemaining *= maxAmount;
                        else
                            item.Amount = maxAmount;
                    }
					
					#region Plant Pigments
					if( item is PlantPigment && ( craftSystem is DefAlchemy || craftSystem is DefCooking ) )
					{
						((PlantPigment)item).PigmentHue = PlantPigmentHueInfo.HueFromPlantHue(m_PlantHue);
					}
					
					if( item is NaturalDye && ( craftSystem is DefAlchemy || craftSystem is DefCooking ) )
					{
						((NaturalDye)item).PigmentHue = PlantPigmentHueInfo.GetInfo(m_PlantPigmentHue).PlantPigmentHue;
					}

                    if (item is SoftenedReeds && (craftSystem is DefAlchemy || craftSystem is DefCooking))
                    {
                        ((SoftenedReeds)item).PlantHue = PlantHueInfo.GetInfo(this.m_PlantHue).PlantHue;
                    }

                    if (item is BaseContainer && (craftSystem is DefBasketweaving))
                    {
                        ((BaseContainer)item).Hue = PlantHueInfo.GetInfo(this.m_PlantHue).Hue;
                    }
					#endregion
					
                    from.AddToBackpack(item);

                    //typeres amount quality  Type resourceType = typeRes;
                    if (!m_UseAllRes)
                    {
                        int m_TokensAmount = 1;

                        if (typeRes != null)
                        {
                            CraftResource thisResource = CraftResources.GetFromType(typeRes);
                            switch (thisResource)
                            {
                                default: m_TokensAmount *= 1; break;
                                case CraftResource.SpinedLeather: m_TokensAmount *= 2; break;
                                case CraftResource.HornedLeather: m_TokensAmount *= 3; break;
                                case CraftResource.BarbedLeather: m_TokensAmount *= 4; break;
                                case CraftResource.DaemonLeather: m_TokensAmount *= 5; break;
                                case CraftResource.DragonLeather: m_TokensAmount *= 6; break;
                                //case CraftResource.BlazeLeather: i_TokensAmount *= 7; break;
                                //case CraftResource.DaemonicLeather: i_TokensAmount *= 8; break;
                                //case CraftResource.ShadowLeather: i_TokensAmount *= 9; break;
                                //case CraftResource.FrostLeather: i_TokensAmount *= 10; break;
                                //case CraftResource.EtherealLeather: i_TokensAmount *= 11; break;
                                case CraftResource.DullCopper: m_TokensAmount *= 2; break;
                                case CraftResource.ShadowIron: m_TokensAmount *= 3; break;
                                case CraftResource.Copper: m_TokensAmount *= 4; break;
                                case CraftResource.Bronze: m_TokensAmount *= 5; break;
                                case CraftResource.Gold: m_TokensAmount *= 6; break;
                                case CraftResource.Agapite: m_TokensAmount *= 7; break;
                                case CraftResource.Verite: m_TokensAmount *= 8; break;
                                case CraftResource.Valorite: m_TokensAmount *= 9; break;
                                case CraftResource.Silver: m_TokensAmount *= 10; break;
                                case CraftResource.Jade: m_TokensAmount *= 11; break;
                                case CraftResource.Moonstone: m_TokensAmount *= 12; break;
                                case CraftResource.Sunstone: m_TokensAmount *= 13; break;
                                //case CraftResource.Platinum: i_TokensAmount *= 14; break;
                                case CraftResource.RedScales: m_TokensAmount *= 2; break;
                                case CraftResource.YellowScales: m_TokensAmount *= 3; break;
                                case CraftResource.BlackScales: m_TokensAmount *= 4; break;
                                case CraftResource.GreenScales: m_TokensAmount *= 5; break;
                                case CraftResource.WhiteScales: m_TokensAmount *= 6; break;
                                case CraftResource.BlueScales: m_TokensAmount *= 7; break;
                                //case CraftResource.CopperScales: i_TokensAmount *= 8; break;
                                //case CraftResource.SilverScales: i_TokensAmount *= 9; break;
                                //case CraftResource.GoldScales: i_TokensAmount *= 10; break;
                                case CraftResource.Pine: m_TokensAmount *= 2; break;
                                case CraftResource.Oak: m_TokensAmount *= 3; break;
                                case CraftResource.Ash: m_TokensAmount *= 4; break;
                                case CraftResource.Yew: m_TokensAmount *= 5; break;
                                //case CraftResource.Oak: m_TokensAmount *= 6; break;
                                case CraftResource.Cherry: m_TokensAmount *= 7; break;
                                case CraftResource.Cedar: m_TokensAmount *= 8; break;
                                case CraftResource.Mahogany: m_TokensAmount *= 9; break;
                                // case CraftResource.PurpleHeart: i_TokensAmount *= 10; break;
                                // case CraftResource.Redwood: i_TokensAmount *= 11; break;
                                // case CraftResource.Petrified: i_TokensAmount *= 12; break;
                                case CraftResource.Heartwood: m_TokensAmount *= 10; break;
                                case CraftResource.Bloodwood: m_TokensAmount *= 11; break;
                                case CraftResource.Frostwood: m_TokensAmount *= 12; break;
                            }
                        }
                        m_TokensAmount *= Ressources.GetAt(0).Amount;
                        double tok = m_TokensAmount;
                        if (quality == 2)
                            tok *= 1.35;
                        tok /= 8;
                        if (tok >= 1)
                            m_TokensAmount = (int)tok;
                        else
                            m_TokensAmount = 1;
                        TokenValidate.RewardTokens(from, m_TokensAmount);
                    }

                    if (from.AccessLevel > AccessLevel.Player)
                        CommandLogging.WriteLine(from, "Crafting {0} with craft system {1}", CommandLogging.Format(item), craftSystem.GetType().Name);

                    //from.PlaySound( 0x57 );
                }

                if (num == 0)
                    num = craftSystem.PlayEndingEffect(from, false, true, toolBroken, endquality, makersMark, this);

                bool queryFactionImbue = false;
                int availableSilver = 0;
                FactionItemDefinition def = null;
                Faction faction = null;

                if (item is IFactionItem)
                {
                    def = FactionItemDefinition.Identify(item);

                    if (def != null)
                    {
                        faction = Faction.Find(from);

                        if (faction != null)
                        {
                            Town town = Town.FromRegion(from.Region);

                            if (town != null && town.Owner == faction)
                            {
                                Container pack = from.Backpack;

                                if (pack != null)
                                {
                                    availableSilver = pack.GetAmount(typeof(Silver));

                                    if (availableSilver >= def.SilverCost)
                                        queryFactionImbue = Faction.IsNearType(from, def.VendorType, 12);
                                }
                            }
                        }
                    }
                }

                // TODO: Scroll imbuing

                if (queryFactionImbue)
                    from.SendGump(new FactionImbueGump(quality, item, from, craftSystem, tool, num, availableSilver, faction, def));
                else if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
                    from.SendGump(new CraftGump(from, craftSystem, tool, num));
                else if (num > 0)
                    from.SendLocalizedMessage(num);
            }
            else if (!allRequiredSkills)
            {
                if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
                    from.SendGump(new CraftGump(from, craftSystem, tool, 1044153));
                else
                    from.SendLocalizedMessage(1044153); // You don't have the required skills to attempt this item.
            }
            else
            {
                ConsumeType consumeType = (UseAllRes ? ConsumeType.Half : ConsumeType.All);
                int resHue = 0;
                int maxAmount = 0;

                object message = null;

                // Not enough resource to craft it
                if (!ConsumeRes(from, typeRes, craftSystem, ref resHue, ref maxAmount, consumeType, ref message, true))
                {
                    if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
                        from.SendGump(new CraftGump(from, craftSystem, tool, message));
                    else if (message is int && (int)message > 0)
                        from.SendLocalizedMessage((int)message);
                    else if (message is string)
                        from.SendMessage((string)message);

                    return;
                }

                tool.UsesRemaining--;

                if (tool.UsesRemaining < 1)
                    toolBroken = true;

                if (toolBroken)
                    tool.Delete();

                // SkillCheck failed.
                int num = craftSystem.PlayEndingEffect(from, true, true, toolBroken, endquality, false, this);

                if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
                    from.SendGump(new CraftGump(from, craftSystem, tool, num));
                else if (num > 0)
                    from.SendLocalizedMessage(num);
            }
        }
Exemple #26
0
		public void CompleteCraft( int quality, bool makersMark, Mobile from, CraftSystem craftSystem, Type typeRes, BaseTool tool, CustomCraft customCraft )
		{
			int badCraft = craftSystem.CanCraft( from, tool, m_Type );

			if ( badCraft > 0 )
			{
				if ( tool != null && !tool.Deleted && tool.UsesRemaining > 0 )
					from.SendGump( new CraftGump( from, craftSystem, tool, badCraft ) );
				else
					from.SendLocalizedMessage( badCraft );

				return;
			}

			int checkResHue = 0, checkMaxAmount = 0;
			object checkMessage = null;

			// Not enough resource to craft it
			if ( !ConsumeRes( from, typeRes, craftSystem, ref checkResHue, ref checkMaxAmount, ConsumeType.None, ref checkMessage ) )
			{
				if ( tool != null && !tool.Deleted && tool.UsesRemaining > 0 )
					from.SendGump( new CraftGump( from, craftSystem, tool, checkMessage ) );
				else if ( checkMessage is int && (int)checkMessage > 0 )
					from.SendLocalizedMessage( (int)checkMessage );
				else if ( checkMessage is string )
					from.SendMessage( (string)checkMessage );

				return;
			}
			else if ( !ConsumeAttributes( from, ref checkMessage, false ) )
			{
				if ( tool != null && !tool.Deleted && tool.UsesRemaining > 0 )
					from.SendGump( new CraftGump( from, craftSystem, tool, checkMessage ) );
				else if ( checkMessage is int && (int)checkMessage > 0 )
					from.SendLocalizedMessage( (int)checkMessage );
				else if ( checkMessage is string )
					from.SendMessage( (string)checkMessage );

				return;
			}

			bool toolBroken = false;

			int ignored = 1;
			int endquality = 1;

			bool allRequiredSkills = true;

			if ( CheckSkills( from, typeRes, craftSystem, ref ignored, ref allRequiredSkills ) )
			{
				// Resource
				int resHue = 0;
				int maxAmount = 0;

				object message = null;

				// Not enough resource to craft it
				if ( !ConsumeRes( from, typeRes, craftSystem, ref resHue, ref maxAmount, ConsumeType.All, ref message ) )
				{
					if ( tool != null && !tool.Deleted && tool.UsesRemaining > 0 )
						from.SendGump( new CraftGump( from, craftSystem, tool, message ) );
					else if ( message is int && (int)message > 0 )
						from.SendLocalizedMessage( (int)message );
					else if ( message is string )
						from.SendMessage( (string)message );

					return;
				}
				else if ( !ConsumeAttributes( from, ref message, true ) )
				{
					if ( tool != null && !tool.Deleted && tool.UsesRemaining > 0 )
						from.SendGump( new CraftGump( from, craftSystem, tool, message ) );
					else if ( message is int && (int)message > 0 )
						from.SendLocalizedMessage( (int)message );
					else if ( message is string )
						from.SendMessage( (string)message );

					return;
				}

				tool.UsesRemaining--;

				if ( craftSystem is DefBlacksmithy )
				{
					AncientSmithyHammer hammer = from.FindItemOnLayer( Layer.OneHanded ) as AncientSmithyHammer;
					if ( hammer != null && hammer != tool )
					{
						hammer.UsesRemaining--;
						if ( hammer.UsesRemaining < 1 )
							hammer.Delete();
					}
				}

				if ( tool.UsesRemaining < 1 )
					toolBroken = true;

				if ( toolBroken )
					tool.Delete();

				int num = 0;

				Item item;
				if ( customCraft != null )
				{
					item = customCraft.CompleteCraft( out num );
				}
				else if ( typeof( MapItem ).IsAssignableFrom( ItemType ) && from.Map != Map.Trammel && from.Map != Map.Felucca )
				{
					item = new IndecipherableMap();
					from.SendLocalizedMessage( 1070800 ); // The map you create becomes mysteriously indecipherable.
				}
				else
				{
					item = Activator.CreateInstance( ItemType ) as Item;
				}

				if ( item != null )
				{
					if( item is ICraftable )
						endquality = ((ICraftable)item).OnCraft( quality, makersMark, from, craftSystem, typeRes, tool, this, resHue );
					else if ( item.Hue == 0 )
						item.Hue = resHue;

					if ( maxAmount > 0 )
					{
						if ( !item.Stackable && item is IUsesRemaining )
							((IUsesRemaining)item).UsesRemaining *= maxAmount;
						else
							item.Amount = maxAmount;
					}

					from.AddToBackpack( item );

					if( from.AccessLevel > AccessLevel.Player )
						CommandLogging.WriteLine( from, "Crafting {0} with craft system {1}", CommandLogging.Format( item ), craftSystem.GetType().Name );

					//from.PlaySound( 0x57 );
				}

				if ( num == 0 )
					num = craftSystem.PlayEndingEffect( from, false, true, toolBroken, endquality, makersMark, this );

				bool queryFactionImbue = false;
				int availableSilver = 0;
				FactionItemDefinition def = null;
				Faction faction = null;

				if ( item is IFactionItem )
				{
					def = FactionItemDefinition.Identify( item );

					if ( def != null )
					{
						faction = Faction.Find( from );

						if ( faction != null )
						{
							Town town = Town.FromRegion( from.Region );

							if ( town != null && town.Owner == faction )
							{
								Container pack = from.Backpack;

								if ( pack != null )
								{
									availableSilver = pack.GetAmount( typeof( Silver ) );

									if ( availableSilver >= def.SilverCost )
										queryFactionImbue = Faction.IsNearType( from, def.VendorType, 12 );
								}
							}
						}
					}
				}

				// TODO: Scroll imbuing

				if ( queryFactionImbue )
					from.SendGump( new FactionImbueGump( quality, item, from, craftSystem, tool, num, availableSilver, faction, def ) );
				else if ( tool != null && !tool.Deleted && tool.UsesRemaining > 0 )
					from.SendGump( new CraftGump( from, craftSystem, tool, num ) );
				else if ( num > 0 )
					from.SendLocalizedMessage( num );
			}
			else if ( !allRequiredSkills )
			{
				if ( tool != null && !tool.Deleted && tool.UsesRemaining > 0 )
					from.SendGump( new CraftGump( from, craftSystem, tool, 1044153 ) );
				else
					from.SendLocalizedMessage( 1044153 ); // You don't have the required skills to attempt this item.
			}
			else
			{
				ConsumeType consumeType = ( UseAllRes ? ConsumeType.Half : ConsumeType.All );
				int resHue = 0;
				int maxAmount = 0;

				object message = null;

				// Not enough resource to craft it
				if ( !ConsumeRes( from, typeRes, craftSystem, ref resHue, ref maxAmount, consumeType, ref message, true ) )
				{
					if ( tool != null && !tool.Deleted && tool.UsesRemaining > 0 )
						from.SendGump( new CraftGump( from, craftSystem, tool, message ) );
					else if ( message is int && (int)message > 0 )
						from.SendLocalizedMessage( (int)message );
					else if ( message is string )
						from.SendMessage( (string)message );

					return;
				}

				tool.UsesRemaining--;

				if ( tool.UsesRemaining < 1 )
					toolBroken = true;

				if ( toolBroken )
					tool.Delete();

				// SkillCheck failed.
				int num = craftSystem.PlayEndingEffect( from, true, true, toolBroken, endquality, false, this );

				if ( tool != null && !tool.Deleted && tool.UsesRemaining > 0 )
					from.SendGump( new CraftGump( from, craftSystem, tool, num ) );
				else if ( num > 0 )
					from.SendLocalizedMessage( num );
			}
		}
        public async void CraftItem(CraftItem item)
        {
            var num = CraftSystem.CanCraft(From, Tool, item.ItemType);

            if (num > 0)
            {
                From.SendGump(new CraftGump(From, CraftSystem, Tool, num));
            }
            else if (From.NextSkillTime > Core.TickCount)
            {
                From.SendGump(new CraftGump(From, CraftSystem, Tool, 1045157)); // You must wait to perform another action.
            }
            else
            {
                Type type = null;

                CraftContext context = CraftSystem.GetContext(From);

                if (context != null)
                {
                    CraftSubResCol res      = item.UseSubRes2 ? CraftSystem.CraftSubRes2 : CraftSystem.CraftSubRes;
                    int            resIndex = item.UseSubRes2 ? context.LastResourceIndex2 : context.LastResourceIndex;

                    if (resIndex >= 0 && resIndex < res.Count)
                    {
                        type = res.GetAt(resIndex).ItemType;
                    }
                }

                var success          = false;
                var fromPrevLocation = From.Location;

                for (var i = context.CraftNumber; i >= 0; i--)
                {
                    if (i == 0)
                    {
                        From.SendAsciiMessage(89, "You finished looping.");
                        return;
                    }

                    var badCraft = CraftSystem.CanCraft(From, Tool, item.ItemType);
                    if (badCraft > 0)
                    {
                        From.SendAsciiMessage(89, "Looping aborted.");
                        return;
                    }

                    if (From.Location != fromPrevLocation)
                    {
                        From.SendAsciiMessage(89, "You moved. Looping aborted.");
                        return;
                    }

                    From.CloseGump <CraftGump>();
                    From.CloseGump <CraftGumpItem>();

                    CraftSystem.CreateItem(From, item.ItemType, type, Tool, item, ref success);

                    if (!success)
                    {
                        return;
                    }

                    From.SendAsciiMessage(89, $"Looping [{i} more to go].");

                    var loopDelay = ((int)(CraftSystem.Delay * CraftSystem.MaxCraftEffect) + (int)ZhConfig.Crafting.AutoLoop.Delay) * 1000;

                    From.NextSkillTime = Core.TickCount + loopDelay;

                    await Timer.Pause(loopDelay);
                }
            }
        }
Exemple #28
0
        public static void CraftItem( CraftItem item, CraftSystem system, Mobile from, BaseTool tool )
        {
            int num = system.CanCraft( from, tool, item.ItemType );
            CraftContext context = system.GetContext( from );

            if ( context == null )
                return;

            if ( num > 0 )
            {
                context.Making = null;

                from.SendGump( new CraftGump( from, system, tool, num ) );
            }
            else
            {
                context.Making = item;

                Type type = null;

                CraftSubResCol res = ( item.UseSubRes2 ? system.CraftSubRes2 : system.CraftSubRes );
                int resIndex = ( item.UseSubRes2 ? context.LastResourceIndex2 : context.LastResourceIndex );

                if ( resIndex >= 0 && resIndex < res.Count )
                    type = res.GetAt( resIndex ).ItemType;

                system.CreateItem( from, item.ItemType, type, tool, item );
            }
        }
Exemple #29
0
		public static EnhanceResult Invoke( Mobile from, CraftSystem craftSystem, BaseTool tool, Item item, CraftResource resource, Type resType, ref object resMessage )
		{
			if ( item == null )
				return EnhanceResult.BadItem;

			if ( !item.IsChildOf( from.Backpack ) )
				return EnhanceResult.NotInBackpack;

			if ( !(item is BaseArmor) && !(item is BaseWeapon) )
				return EnhanceResult.BadItem;

			if ( CraftResources.IsStandard( resource ) )
				return EnhanceResult.BadResource;
			
			int num = craftSystem.CanCraft( from, tool, item.GetType() );
			
			if ( num > 0 )
			{
				resMessage = num;
				return EnhanceResult.None;
			}

			CraftItem craftItem = craftSystem.CraftItems.SearchFor( item.GetType() );

			if ( craftItem == null || craftItem.Resources.Count == 0 )
				return EnhanceResult.BadItem;

			#region Mondain's Legacy
			if ( craftItem.ForceNonExceptional )
				return EnhanceResult.BadItem;
			#endregion

			bool allRequiredSkills = false;
			if( craftItem.GetSuccessChance( from, resType, craftSystem, false, ref allRequiredSkills ) <= 0.0 )
				return EnhanceResult.NoSkill;

			CraftResourceInfo info = CraftResources.GetInfo( resource );

			if ( info == null || info.ResourceTypes.Length == 0 )
				return EnhanceResult.BadResource;

			CraftAttributeInfo attributes = info.AttributeInfo;

			if ( attributes == null )
				return EnhanceResult.BadResource;

			int resHue = 0, maxAmount = 0;

			if ( !craftItem.ConsumeRes( from, resType, craftSystem, ref resHue, ref maxAmount, ConsumeType.None, ref resMessage ) )
				return EnhanceResult.NoResources;

			if ( craftSystem is DefBlacksmithy )
			{
				AncientSmithyHammer hammer = from.FindItemOnLayer( Layer.OneHanded ) as AncientSmithyHammer;
				if ( hammer != null )
				{
					hammer.UsesRemaining--;
					if ( hammer.UsesRemaining < 1 )
						hammer.Delete();
				}
			}

			int phys = 0, fire = 0, cold = 0, pois = 0, nrgy = 0;
			int dura = 0, luck = 0, lreq = 0, dinc = 0;
			int baseChance = 0;

			bool physBonus = false;
			bool fireBonus = false;
			bool coldBonus = false;
			bool nrgyBonus = false;
			bool poisBonus = false;
			bool duraBonus = false;
			bool luckBonus = false;
			bool lreqBonus = false;
			bool dincBonus = false;

			if ( item is BaseWeapon )
			{
				BaseWeapon weapon = (BaseWeapon)item;

				if ( !CraftResources.IsStandard( weapon.Resource ) )
					return EnhanceResult.AlreadyEnhanced;

				baseChance = 20;

				dura = weapon.MaxHitPoints;
				luck = weapon.Attributes.Luck;
				lreq = weapon.WeaponAttributes.LowerStatReq;
				dinc = weapon.Attributes.WeaponDamage;

				fireBonus = ( attributes.WeaponFireDamage > 0 );
				coldBonus = ( attributes.WeaponColdDamage > 0 );
				nrgyBonus = ( attributes.WeaponEnergyDamage > 0 );
				poisBonus = ( attributes.WeaponPoisonDamage > 0 );

				duraBonus = ( attributes.WeaponDurability > 0 );
				luckBonus = ( attributes.WeaponLuck > 0 );
				lreqBonus = ( attributes.WeaponLowerRequirements > 0 );
				dincBonus = ( dinc > 0 );
			}
			else
			{
				BaseArmor armor = (BaseArmor)item;

				if ( !CraftResources.IsStandard( armor.Resource ) )
					return EnhanceResult.AlreadyEnhanced;

				baseChance = 20;

				phys = armor.PhysicalResistance;
				fire = armor.FireResistance;
				cold = armor.ColdResistance;
				pois = armor.PoisonResistance;
				nrgy = armor.EnergyResistance;

				dura = armor.MaxHitPoints;
				luck = armor.Attributes.Luck;
				lreq = armor.ArmorAttributes.LowerStatReq;

				physBonus = ( attributes.ArmorPhysicalResist > 0 );
				fireBonus = ( attributes.ArmorFireResist > 0 );
				coldBonus = ( attributes.ArmorColdResist > 0 );
				nrgyBonus = ( attributes.ArmorEnergyResist > 0 );
				poisBonus = ( attributes.ArmorPoisonResist > 0 );

				duraBonus = ( attributes.ArmorDurability > 0 );
				luckBonus = ( attributes.ArmorLuck > 0 );
				lreqBonus = ( attributes.ArmorLowerRequirements > 0 );
				dincBonus = false;
			}

			int skill = from.Skills[craftSystem.MainSkill].Fixed / 10;

			if ( skill >= 100 )
				baseChance -= (skill - 90) / 10;

			EnhanceResult res = EnhanceResult.Success;

			if ( physBonus )
				CheckResult( ref res, baseChance + phys );

			if ( fireBonus )
				CheckResult( ref res, baseChance + fire );

			if ( coldBonus )
				CheckResult( ref res, baseChance + cold );

			if ( nrgyBonus )
				CheckResult( ref res, baseChance + nrgy );

			if ( poisBonus )
				CheckResult( ref res, baseChance + pois );

			if ( duraBonus )
				CheckResult( ref res, baseChance + (dura / 40) );

			if ( luckBonus )
				CheckResult( ref res, baseChance + 10 + (luck / 2) );

			if ( lreqBonus )
				CheckResult( ref res, baseChance + (lreq / 4) );

			if ( dincBonus )
				CheckResult( ref res, baseChance + (dinc / 4) );

			switch ( res )
			{
				case EnhanceResult.Broken:
				{
					if ( !craftItem.ConsumeRes( from, resType, craftSystem, ref resHue, ref maxAmount, ConsumeType.Half, ref resMessage ) )
						return EnhanceResult.NoResources;

					item.Delete();
					break;
				}
				case EnhanceResult.Success:
				{
					if ( !craftItem.ConsumeRes( from, resType, craftSystem, ref resHue, ref maxAmount, ConsumeType.All, ref resMessage ) )
						return EnhanceResult.NoResources;

					if( item is BaseWeapon )
					{
						BaseWeapon w = (BaseWeapon)item;

						w.Resource = resource;

						#region Mondain's Legacy
						if ( resource != CraftResource.Heartwood )
						{
							w.Attributes.WeaponDamage += attributes.WeaponDamage;
							w.Attributes.WeaponSpeed += attributes.WeaponSwingSpeed;
							w.Attributes.AttackChance += attributes.WeaponHitChance;
							w.Attributes.RegenHits += attributes.WeaponRegenHits;			
							w.WeaponAttributes.HitLeechHits += attributes.WeaponHitLifeLeech;
						}
						else
						{
							switch ( Utility.Random( 6 ) )
							{
								case 0: w.Attributes.WeaponDamage += attributes.WeaponDamage; break;
								case 1: w.Attributes.WeaponSpeed += attributes.WeaponSwingSpeed; break;
								case 2: w.Attributes.AttackChance += attributes.WeaponHitChance; break;
								case 3: w.Attributes.Luck += attributes.WeaponLuck; break;
								case 4: w.WeaponAttributes.LowerStatReq += attributes.WeaponLowerRequirements; break;
								case 5: w.WeaponAttributes.HitLeechHits += attributes.WeaponHitLifeLeech; break;
							}
						}
						#endregion

						int hue = w.GetElementalDamageHue();
						if( hue > 0 )
							w.Hue = hue;
					}
					#region Mondain's Legacy
					else if ( item is BaseShield )
					{
						BaseShield shield = (BaseShield) item;

						shield.Resource = resource;

						switch ( resource )
						{
							case CraftResource.AshWood: 
								shield.ArmorAttributes.LowerStatReq += 20; 
								break;

							case CraftResource.YewWood: 
								shield.Attributes.RegenHits += 1; 
								break;

							case CraftResource.Heartwood:
								switch ( Utility.Random( 7 ) )
								{
									case 0: shield.Attributes.BonusDex += 2; break;
									case 1: shield.Attributes.BonusStr += 2; break; 
									case 2: shield.Attributes.ReflectPhysical += 5; break;
									case 3: shield.Attributes.SpellChanneling = 1; shield.Attributes.CastSpeed = -1; break;
									case 4: shield.ArmorAttributes.SelfRepair += 2; break;			
									case 5: shield.PhysicalBonus += 5; break;
									case 6: shield.ColdBonus += 3; break;
								}
								break;

							case CraftResource.Bloodwood: 
								shield.Attributes.RegenHits += 2;
								shield.Attributes.Luck += 40;
								break;

							case CraftResource.Frostwood:
								shield.Attributes.SpellChanneling = 1; 
								shield.Attributes.CastSpeed = -1;
								break;
						}
					}
					#endregion
					else if( item is BaseArmor )	//Sanity
					{
						((BaseArmor)item).Resource = resource;

						#region Mondain's Legacy
						BaseArmor armor = (BaseArmor) item;

						if ( resource != CraftResource.Heartwood )
						{
							armor.Attributes.WeaponDamage += attributes.ArmorDamage;
							armor.Attributes.AttackChance += attributes.ArmorHitChance;
							armor.Attributes.RegenHits += attributes.ArmorRegenHits;				
							armor.ArmorAttributes.MageArmor += attributes.ArmorMage;
						}
						else
						{
							switch ( Utility.Random( 5 ) )
							{
								case 0: armor.Attributes.WeaponDamage += attributes.ArmorDamage; break;
								case 1: armor.Attributes.AttackChance += attributes.ArmorHitChance; break;
								case 2: armor.ArmorAttributes.MageArmor += attributes.ArmorMage; break;			 
								case 3: armor.Attributes.Luck += attributes.ArmorLuck; break;
								case 4: armor.ArmorAttributes.LowerStatReq += attributes.ArmorLowerRequirements; break;
							}
						}
						#endregion
					}

					break;
				}
				case EnhanceResult.Failure:
				{
					if ( !craftItem.ConsumeRes( from, resType, craftSystem, ref resHue, ref maxAmount, ConsumeType.Half, ref resMessage ) )
						return EnhanceResult.NoResources;

					break;
				}
			}

			return res;
		}
Exemple #30
0
        public static EnhanceResult Invoke(Mobile from, CraftSystem craftSystem, BaseTool tool, Item item, CraftResource resource, Type resType, ref object resMessage)
        {
            if (item == null)
            {
                return(EnhanceResult.BadItem);
            }

            if (!item.IsChildOf(from.Backpack))
            {
                return(EnhanceResult.NotInBackpack);
            }

            if (!(item is BaseArmor) && !(item is BaseWeapon))
            {
                return(EnhanceResult.BadItem);
            }

            if (item is IArcaneEquip)
            {
                IArcaneEquip eq = (IArcaneEquip)item;
                if (eq.IsArcane)
                {
                    return(EnhanceResult.BadItem);
                }
            }

            if (CraftResources.IsStandard(resource))
            {
                return(EnhanceResult.BadResource);
            }

            int num = craftSystem.CanCraft(from, tool, item.GetType());

            if (num > 0)
            {
                resMessage = num;
                return(EnhanceResult.None);
            }

            CraftItem craftItem = craftSystem.CraftItems.SearchFor(item.GetType());

            if (IsSpecial(item, craftSystem))
            {
                craftItem = craftSystem.CraftItems.SearchForSubclass(item.GetType());
            }

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

            #region Mondain's Legacy
            if (craftItem.ForceNonExceptional)
            {
                return(EnhanceResult.BadItem);
            }
            #endregion

            bool allRequiredSkills = false;
            if (craftItem.GetSuccessChance(from, resType, craftSystem, false, ref allRequiredSkills) <= 0.0)
            {
                return(EnhanceResult.NoSkill);
            }

            CraftResourceInfo info = CraftResources.GetInfo(resource);

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

            CraftAttributeInfo attributes = info.AttributeInfo;

            if (attributes == null)
            {
                return(EnhanceResult.BadResource);
            }

            int resHue = 0, maxAmount = 0;

            if (!craftItem.ConsumeRes(from, resType, craftSystem, ref resHue, ref maxAmount, ConsumeType.None, ref resMessage))
            {
                return(EnhanceResult.NoResources);
            }

            if (craftSystem is DefBlacksmithy)
            {
                AncientSmithyHammer hammer = from.FindItemOnLayer(Layer.OneHanded) as AncientSmithyHammer;
                if (hammer != null)
                {
                    hammer.UsesRemaining--;
                    if (hammer.UsesRemaining < 1)
                    {
                        hammer.Delete();
                    }
                }
            }

            int phys = 0, fire = 0, cold = 0, pois = 0, nrgy = 0;
            int dura = 0, luck = 0, lreq = 0, dinc = 0;
            int baseChance = 0;

            bool physBonus = false;
            bool fireBonus = false;
            bool coldBonus = false;
            bool nrgyBonus = false;
            bool poisBonus = false;
            bool duraBonus = false;
            bool luckBonus = false;
            bool lreqBonus = false;
            bool dincBonus = false;

            if (item is BaseWeapon)
            {
                BaseWeapon weapon = (BaseWeapon)item;

                if (!CraftResources.IsStandard(weapon.Resource))
                {
                    return(EnhanceResult.AlreadyEnhanced);
                }

                if (weapon.ExtendedWeaponAttributes.AssassinHoned > 0)
                {
                    return(EnhanceResult.BadItem);
                }

                baseChance = 20;

                dura = weapon.MaxHitPoints;
                luck = weapon.Attributes.Luck;
                lreq = weapon.WeaponAttributes.LowerStatReq;
                dinc = weapon.Attributes.WeaponDamage;

                fireBonus = (attributes.WeaponFireDamage > 0);
                coldBonus = (attributes.WeaponColdDamage > 0);
                nrgyBonus = (attributes.WeaponEnergyDamage > 0);
                poisBonus = (attributes.WeaponPoisonDamage > 0);

                duraBonus = (attributes.WeaponDurability > 0);
                luckBonus = (attributes.WeaponLuck > 0);
                lreqBonus = (attributes.WeaponLowerRequirements > 0);
                dincBonus = (dinc > 0);
            }
            else
            {
                BaseArmor armor = (BaseArmor)item;

                if (!CraftResources.IsStandard(armor.Resource))
                {
                    return(EnhanceResult.AlreadyEnhanced);
                }

                baseChance = 20;

                phys = armor.PhysicalResistance;
                fire = armor.FireResistance;
                cold = armor.ColdResistance;
                pois = armor.PoisonResistance;
                nrgy = armor.EnergyResistance;

                dura = armor.MaxHitPoints;
                luck = armor.Attributes.Luck;
                lreq = armor.ArmorAttributes.LowerStatReq;

                physBonus = (attributes.ArmorPhysicalResist > 0);
                fireBonus = (attributes.ArmorFireResist > 0);
                coldBonus = (attributes.ArmorColdResist > 0);
                nrgyBonus = (attributes.ArmorEnergyResist > 0);
                poisBonus = (attributes.ArmorPoisonResist > 0);

                duraBonus = (attributes.ArmorDurability > 0);
                luckBonus = (attributes.ArmorLuck > 0);
                lreqBonus = (attributes.ArmorLowerRequirements > 0);
                dincBonus = false;
            }

            int skill = from.Skills[craftSystem.MainSkill].Fixed / 10;

            if (skill >= 100)
            {
                baseChance -= (skill - 90) / 10;
            }

            EnhanceResult res = EnhanceResult.Success;

            PlayerMobile user = from as PlayerMobile;

            if (physBonus)
            {
                CheckResult(ref res, baseChance + phys);
            }

            if (fireBonus)
            {
                CheckResult(ref res, baseChance + fire);
            }

            if (coldBonus)
            {
                CheckResult(ref res, baseChance + cold);
            }

            if (nrgyBonus)
            {
                CheckResult(ref res, baseChance + nrgy);
            }

            if (poisBonus)
            {
                CheckResult(ref res, baseChance + pois);
            }

            if (duraBonus)
            {
                CheckResult(ref res, baseChance + (dura / 40));
            }

            if (luckBonus)
            {
                CheckResult(ref res, baseChance + 10 + (luck / 2));
            }

            if (lreqBonus)
            {
                CheckResult(ref res, baseChance + (lreq / 4));
            }

            if (dincBonus)
            {
                CheckResult(ref res, baseChance + (dinc / 4));
            }

            if (user.NextEnhanceSuccess)
            {
                user.NextEnhanceSuccess = false;
                user.SendLocalizedMessage(1149969); // The magical aura that surrounded you disipates and you feel that your item enhancement chances have returned to normal.
                res = EnhanceResult.Success;
            }

            switch (res)
            {
            case EnhanceResult.Broken:
            {
                if (!craftItem.ConsumeRes(from, resType, craftSystem, ref resHue, ref maxAmount, ConsumeType.Half, ref resMessage))
                {
                    return(EnhanceResult.NoResources);
                }

                item.Delete();
                break;
            }

            case EnhanceResult.Success:
            {
                if (!craftItem.ConsumeRes(from, resType, craftSystem, ref resHue, ref maxAmount, ConsumeType.All, ref resMessage))
                {
                    return(EnhanceResult.NoResources);
                }

                if (item is BaseWeapon)
                {
                    BaseWeapon w = (BaseWeapon)item;

                    w.Resource = resource;

                    #region Mondain's Legacy
                    if (resource != CraftResource.Heartwood)
                    {
                        w.Attributes.WeaponDamage       += attributes.WeaponDamage;
                        w.Attributes.WeaponSpeed        += attributes.WeaponSwingSpeed;
                        w.Attributes.AttackChance       += attributes.WeaponHitChance;
                        w.Attributes.RegenHits          += attributes.WeaponRegenHits;
                        w.WeaponAttributes.HitLeechHits += attributes.WeaponHitLifeLeech;
                    }
                    else
                    {
                        switch (Utility.Random(6))
                        {
                        case 0:
                            w.Attributes.WeaponDamage += attributes.WeaponDamage;
                            break;

                        case 1:
                            w.Attributes.WeaponSpeed += attributes.WeaponSwingSpeed;
                            break;

                        case 2:
                            w.Attributes.AttackChance += attributes.WeaponHitChance;
                            break;

                        case 3:
                            w.Attributes.Luck += attributes.WeaponLuck;
                            break;

                        case 4:
                            w.WeaponAttributes.LowerStatReq += attributes.WeaponLowerRequirements;
                            break;

                        case 5:
                            w.WeaponAttributes.HitLeechHits += attributes.WeaponHitLifeLeech;
                            break;
                        }
                    }
                    #endregion

                    int hue = w.GetElementalDamageHue();
                    if (hue > 0)
                    {
                        w.Hue = hue;
                    }
                }
                #region Mondain's Legacy
                else if (item is BaseShield)
                {
                    BaseShield shield = (BaseShield)item;

                    shield.Resource = resource;

                    switch (resource)
                    {
                    case CraftResource.AshWood:
                        shield.ArmorAttributes.LowerStatReq += 20;
                        break;

                    case CraftResource.YewWood:
                        shield.Attributes.RegenHits += 1;
                        break;

                    case CraftResource.Heartwood:
                        switch (Utility.Random(7))
                        {
                        case 0:
                            shield.Attributes.BonusDex += 2;
                            break;

                        case 1:
                            shield.Attributes.BonusStr += 2;
                            break;

                        case 2:
                            shield.Attributes.ReflectPhysical += 5;
                            break;

                        case 3:
                            shield.Attributes.SpellChanneling = 1;
                            shield.Attributes.CastSpeed       = -1;
                            break;

                        case 4:
                            shield.ArmorAttributes.SelfRepair += 2;
                            break;

                        case 5:
                            shield.PhysicalBonus += 5;
                            break;

                        case 6:
                            shield.ColdBonus += 3;
                            break;
                        }
                        break;

                    case CraftResource.Bloodwood:
                        shield.Attributes.RegenHits += 2;
                        shield.Attributes.Luck      += 40;
                        break;

                    case CraftResource.Frostwood:
                        shield.Attributes.SpellChanneling = 1;
                        shield.Attributes.CastSpeed       = -1;
                        break;
                    }
                }
                #endregion
                else if (item is BaseArmor)             //Sanity
                {
                    ((BaseArmor)item).Resource = resource;

                    #region Mondain's Legacy
                    BaseArmor armor = (BaseArmor)item;

                    if (resource != CraftResource.Heartwood)
                    {
                        armor.Attributes.WeaponDamage += attributes.ArmorDamage;
                        armor.Attributes.AttackChance += attributes.ArmorHitChance;
                        armor.Attributes.RegenHits    += attributes.ArmorRegenHits;
                        //armor.ArmorAttributes.MageArmor += attributes.ArmorMage;
                    }
                    else
                    {
                        switch (Utility.Random(5))
                        {
                        case 0:
                            armor.Attributes.WeaponDamage += attributes.ArmorDamage;
                            break;

                        case 1:
                            armor.Attributes.AttackChance += attributes.ArmorHitChance;
                            break;

                        case 2:
                            armor.ArmorAttributes.MageArmor += attributes.ArmorMage;
                            break;

                        case 3:
                            armor.Attributes.Luck += attributes.ArmorLuck;
                            break;

                        case 4:
                            armor.ArmorAttributes.LowerStatReq += attributes.ArmorLowerRequirements;
                            break;
                        }
                    }
                    #endregion
                }

                break;
            }

            case EnhanceResult.Failure:
            {
                if (!craftItem.ConsumeRes(from, resType, craftSystem, ref resHue, ref maxAmount, ConsumeType.Half, ref resMessage))
                {
                    return(EnhanceResult.NoResources);
                }

                break;
            }
            }

            return(res);
        }
        public void CompleteCraft(int quality, bool makersMark, Mobile from, CraftSystem craftSystem, Type typeRes, BaseTool tool, CustomCraft customCraft)
        {
            int badCraft = craftSystem.CanCraft(from, tool, m_Type);

            if (badCraft > 0)
            {
                if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
                {
                    from.SendGump(new CraftGump(from, craftSystem, tool, badCraft));
                }
                else
                {
                    from.SendLocalizedMessage(badCraft);
                }

                return;
            }

            int    checkResHue = 0, checkMaxAmount = 0;
            object checkMessage = null;

            // Not enough resource to craft it
            if (!ConsumeRes(from, typeRes, craftSystem, ref checkResHue, ref checkMaxAmount, ConsumeType.None, ref checkMessage))
            {
                if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
                {
                    from.SendGump(new CraftGump(from, craftSystem, tool, checkMessage));
                }
                else if (checkMessage is int && (int)checkMessage > 0)
                {
                    from.SendLocalizedMessage((int)checkMessage);
                }
                else if (checkMessage is string)
                {
                    from.SendMessage((string)checkMessage);
                }

                return;
            }
            else if (!ConsumeAttributes(from, ref checkMessage, false))
            {
                if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
                {
                    from.SendGump(new CraftGump(from, craftSystem, tool, checkMessage));
                }
                else if (checkMessage is int && (int)checkMessage > 0)
                {
                    from.SendLocalizedMessage((int)checkMessage);
                }
                else if (checkMessage is string)
                {
                    from.SendMessage((string)checkMessage);
                }

                return;
            }

            bool toolBroken = false;

            int ignored    = 1;
            int endquality = 1;

            bool allRequiredSkills = true;

            if (CheckSkills(from, typeRes, craftSystem, ref ignored, ref allRequiredSkills))
            {
                // Resource
                int resHue    = 0;
                int maxAmount = 0;

                object message = null;

                // Not enough resource to craft it
                if (!ConsumeRes(from, typeRes, craftSystem, ref resHue, ref maxAmount, ConsumeType.All, ref message))
                {
                    if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
                    {
                        from.SendGump(new CraftGump(from, craftSystem, tool, message));
                    }
                    else if (message is int && (int)message > 0)
                    {
                        from.SendLocalizedMessage((int)message);
                    }
                    else if (message is string)
                    {
                        from.SendMessage((string)message);
                    }

                    return;
                }
                else if (!ConsumeAttributes(from, ref message, true))
                {
                    if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
                    {
                        from.SendGump(new CraftGump(from, craftSystem, tool, message));
                    }
                    else if (message is int && (int)message > 0)
                    {
                        from.SendLocalizedMessage((int)message);
                    }
                    else if (message is string)
                    {
                        from.SendMessage((string)message);
                    }

                    return;
                }

                tool.UsesRemaining--;

                if (craftSystem is DefBlacksmithy)
                {
                    AncientSmithyHammer hammer = from.FindItemOnLayer(Layer.OneHanded) as AncientSmithyHammer;
                    if (hammer != null && hammer != tool)
                    {
                        hammer.UsesRemaining--;
                        if (hammer.UsesRemaining < 1)
                        {
                            hammer.Delete();
                        }
                    }
                }

                if (tool.UsesRemaining < 1)
                {
                    toolBroken = true;
                }

                if (toolBroken)
                {
                    tool.Delete();
                }

                int num = 0;

                Item item;
                if (customCraft != null)
                {
                    item = customCraft.CompleteCraft(out num);
                }
                else if (typeof(MapItem).IsAssignableFrom(ItemType) && from.Map != Map.Trammel && from.Map != Map.Felucca)
                {
                    item = new IndecipherableMap();
                    from.SendLocalizedMessage(1070800);                       // The map you create becomes mysteriously indecipherable.
                }
                else
                {
                    item = Activator.CreateInstance(ItemType) as Item;
                }

                if (item != null)
                {
                    if (item is ICraftable)
                    {
                        endquality = ((ICraftable)item).OnCraft(quality, makersMark, from, craftSystem, typeRes, tool, this, resHue);
                    }
                    else if (item.Hue == 0)
                    {
                        item.Hue = resHue;
                    }

                    if (maxAmount > 0)
                    {
                        if (!item.Stackable && item is IUsesRemaining)
                        {
                            ((IUsesRemaining)item).UsesRemaining *= maxAmount;
                        }
                        else
                        {
                            item.Amount = maxAmount;
                        }
                    }

                    from.AddToBackpack(item);

                    if (from.AccessLevel > AccessLevel.Player)
                    {
                        CommandLogging.WriteLine(from, "Crafting {0} with craft system {1}", CommandLogging.Format(item), craftSystem.GetType().Name);
                    }

                    //from.PlaySound( 0x57 );
                }

                if (num == 0)
                {
                    num = craftSystem.PlayEndingEffect(from, false, true, toolBroken, endquality, makersMark, this);
                }

                bool queryFactionImbue    = false;
                int  availableSilver      = 0;
                FactionItemDefinition def = null;
                Faction faction           = null;

                if (item is IFactionItem)
                {
                    def = FactionItemDefinition.Identify(item);

                    if (def != null)
                    {
                        faction = Faction.Find(from);

                        if (faction != null)
                        {
                            Town town = Town.FromRegion(from.Region);

                            if (town != null && town.Owner == faction)
                            {
                                Container pack = from.Backpack;

                                if (pack != null)
                                {
                                    availableSilver = pack.GetAmount(typeof(Silver));

                                    if (availableSilver >= def.SilverCost)
                                    {
                                        queryFactionImbue = Faction.IsNearType(from, def.VendorType, 12);
                                    }
                                }
                            }
                        }
                    }
                }

                // TODO: Scroll imbuing

                if (queryFactionImbue)
                {
                    from.SendGump(new FactionImbueGump(quality, item, from, craftSystem, tool, num, availableSilver, faction, def));
                }
                else if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
                {
                    from.SendGump(new CraftGump(from, craftSystem, tool, num));
                }
                else if (num > 0)
                {
                    from.SendLocalizedMessage(num);
                }
            }
            else if (!allRequiredSkills)
            {
                if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
                {
                    from.SendGump(new CraftGump(from, craftSystem, tool, 1044153));
                }
                else
                {
                    from.SendLocalizedMessage(1044153);                       // You don't have the required skills to attempt this item.
                }
            }
            else
            {
                ConsumeType consumeType = (UseAllRes ? ConsumeType.Half : ConsumeType.All);
                int         resHue      = 0;
                int         maxAmount   = 0;

                object message = null;

                // Not enough resource to craft it
                if (!ConsumeRes(from, typeRes, craftSystem, ref resHue, ref maxAmount, consumeType, ref message, true))
                {
                    if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
                    {
                        from.SendGump(new CraftGump(from, craftSystem, tool, message));
                    }
                    else if (message is int && (int)message > 0)
                    {
                        from.SendLocalizedMessage((int)message);
                    }
                    else if (message is string)
                    {
                        from.SendMessage((string)message);
                    }

                    return;
                }

                tool.UsesRemaining--;

                if (tool.UsesRemaining < 1)
                {
                    toolBroken = true;
                }

                if (toolBroken)
                {
                    tool.Delete();
                }

                // SkillCheck failed.
                int num = craftSystem.PlayEndingEffect(from, true, true, toolBroken, endquality, false, this);

                if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
                {
                    from.SendGump(new CraftGump(from, craftSystem, tool, num));
                }
                else if (num > 0)
                {
                    from.SendLocalizedMessage(num);
                }
            }
        }
Exemple #32
0
		public static EnhanceResult Invoke( Mobile from, CraftSystem craftSystem, BaseTool tool, Item item, CraftResource resource, Type resType, ref object resMessage )
		{
			if( item == null )
				return EnhanceResult.BadItem;

			if( !item.IsChildOf( from.Backpack ) )
				return EnhanceResult.NotInBackpack;

			if( !(item is BaseArmor) && !(item is BaseWeapon) )
				return EnhanceResult.BadItem;

			if( CraftResources.IsStandard( resource ) )
				return EnhanceResult.BadResource;

			int num = craftSystem.CanCraft( from, tool, item.GetType() );
			
			if ( num > 0 )
			{
				resMessage = num;
				return EnhanceResult.None;
			}

			CraftItem craftItem = craftSystem.CraftItems.SearchFor( item.GetType() );

			if ( craftItem == null || craftItem.Resources.Count == 0 )
				return EnhanceResult.BadItem;

			bool allRequiredSkills = false;
			if( craftItem.GetSuccessChance( from, resType, craftSystem, false, ref allRequiredSkills ) <= 0.0 )
				return EnhanceResult.NoSkill;

			CraftResourceInfo info = CraftResources.GetInfo( resource );

			if( info == null || info.ResourceTypes.Length == 0 )
				return EnhanceResult.BadResource;

			CraftAttributeInfo attributes = info.AttributeInfo;

			if( attributes == null )
				return EnhanceResult.BadResource;

			int resHue = 0, maxAmount = 0;

			if( !craftItem.ConsumeRes( from, resType, craftSystem, ref resHue, ref maxAmount, ConsumeType.None, ref resMessage ) )
				return EnhanceResult.NoResources;

			if( craftSystem is DefBlacksmithy )
			{
				AncientSmithyHammer hammer = from.FindItemOnLayer( Layer.OneHanded ) as AncientSmithyHammer;
				if( hammer != null )
				{
					hammer.UsesRemaining--;
					if( hammer.UsesRemaining < 1 )
						hammer.Delete();
				}
			}

			int phys = 0, fire = 0, cold = 0, pois = 0, nrgy = 0;
			int dura = 0, dinc = 0;
			int baseChance = 0;

			bool physBonus = false;
			bool fireBonus = false;
			bool coldBonus = false;
			bool nrgyBonus = false;
			bool poisBonus = false;
			bool duraBonus = false;
			bool dincBonus = false;

			double arms = from.Skills[SkillName.ArmsLore].Base;

			if( item is BaseWeapon )
			{
				BaseWeapon weapon = (BaseWeapon)item;

				if( !CraftResources.IsStandard( weapon.Resource ) )
					return EnhanceResult.AlreadyEnhanced;

				if( arms >= 100.1 )
					baseChance = Utility.RandomMinMax( 2, 5 );
				else if( arms >= 80.1 && arms <= 100 )
					baseChance = Utility.RandomMinMax( 8, 14 );
				else if( arms >= 50 && arms <= 80 )
					baseChance = Utility.RandomMinMax( 16, 20 );
				else
					baseChance = 25;
			}
			else
			{
				BaseArmor armor = (BaseArmor)item;

				if( !CraftResources.IsStandard( armor.Resource ) )
					return EnhanceResult.AlreadyEnhanced;

				if( arms >= 100.1 )
					baseChance = Utility.RandomMinMax( 2, 5 );
				else if( arms >= 80.1 && arms <= 100 )
					baseChance = Utility.RandomMinMax( 8, 14 );
				else if( arms >= 50 && arms <= 80 )
					baseChance = Utility.RandomMinMax( 16, 20 );
				else
					baseChance = 25;

				phys = armor.PhysicalResistance;
				fire = armor.FireResistance;
				cold = armor.ColdResistance;
				pois = armor.PoisonResistance;
				nrgy = armor.EnergyResistance;

				dura = armor.MaxHitPoints;

				physBonus = (attributes.ArmorPhysicalResist > 4);
				fireBonus = (attributes.ArmorFireResist > 5);
				coldBonus = (attributes.ArmorColdResist > 7);
				nrgyBonus = (attributes.ArmorEnergyResist > 2);
				poisBonus = (attributes.ArmorPoisonResist > 1);

				duraBonus = (attributes.ArmorDurability > 0);
				dincBonus = true;
			}

			/*int skill = from.Skills[craftSystem.MainSkill].Fixed / 10;

			if ( skill >= 100 )
				baseChance -= (skill - 90) / 10;*/

			EnhanceResult res = EnhanceResult.Success;

			if( physBonus )
				CheckResult( ref res, baseChance + phys );

			if( fireBonus )
				CheckResult( ref res, baseChance + fire );

			if( coldBonus )
				CheckResult( ref res, baseChance + cold );

			if( nrgyBonus )
				CheckResult( ref res, baseChance + nrgy );

			if( poisBonus )
				CheckResult( ref res, baseChance + pois );

			if( duraBonus )
				CheckResult( ref res, baseChance + (dura / 20) );

			if( dincBonus )
				CheckResult( ref res, baseChance + (dinc / 5) );

			switch( res )
			{
				case EnhanceResult.Broken:
					{
						if( !craftItem.ConsumeRes( from, resType, craftSystem, ref resHue, ref maxAmount, ConsumeType.Half, ref resMessage ) )
							return EnhanceResult.NoResources;

						item.Delete();
						break;
					}
				case EnhanceResult.Success:
					{
						if( !craftItem.ConsumeRes( from, resType, craftSystem, ref resHue, ref maxAmount, ConsumeType.All, ref resMessage ) )
							return EnhanceResult.NoResources;

						if( item is BaseWeapon )
							((BaseWeapon)item).Resource = resource;
						else
							((BaseArmor)item).Resource = resource;

						break;
					}
				case EnhanceResult.Failure:
					{
						if( !craftItem.ConsumeRes( from, resType, craftSystem, ref resHue, ref maxAmount, ConsumeType.Half, ref resMessage ) )
							return EnhanceResult.NoResources;

						break;
					}
			}

			return res;
		}
Exemple #33
0
        public static EnhanceResult Invoke(
            Mobile from, CraftSystem craftSystem, BaseTool tool, Item item,
            CraftResource resource, Type resType, ref TextDefinition resMessage
            )
        {
            if (item == null)
            {
                return(EnhanceResult.BadItem);
            }

            if (!item.IsChildOf(from.Backpack))
            {
                return(EnhanceResult.NotInBackpack);
            }

            if (item is not BaseArmor && item is not BaseWeapon)
            {
                return(EnhanceResult.BadItem);
            }

            if (item is IArcaneEquip eq && eq.IsArcane)
            {
                return(EnhanceResult.BadItem);
            }

            if (CraftResources.IsStandard(resource))
            {
                return(EnhanceResult.BadResource);
            }

            var num = craftSystem.CanCraft(from, tool, item.GetType());

            if (num > 0)
            {
                resMessage = num;
                return(EnhanceResult.None);
            }

            var craftItem = craftSystem.CraftItems.SearchFor(item.GetType());

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

            if (craftItem.GetSuccessChance(from, resType, craftSystem, false, out _) <= 0.0)
            {
                return(EnhanceResult.NoSkill);
            }

            var info = CraftResources.GetInfo(resource);

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

            var attributes = info.AttributeInfo;

            if (attributes == null)
            {
                return(EnhanceResult.BadResource);
            }

            int resHue = 0, maxAmount = 0;

            if (!craftItem.ConsumeRes(
                    from,
                    resType,
                    craftSystem,
                    ref resHue,
                    ref maxAmount,
                    ConsumeType.None,
                    ref resMessage
                    ))
            {
                return(EnhanceResult.NoResources);
            }

            if (craftSystem is DefBlacksmithy)
            {
                if (from.FindItemOnLayer(Layer.OneHanded) is AncientSmithyHammer hammer)
                {
                    hammer.UsesRemaining--;
                    if (hammer.UsesRemaining < 1)
                    {
                        hammer.Delete();
                    }
                }
            }

            int phys = 0, fire = 0, cold = 0, pois = 0, nrgy = 0;
            int dura, luck, lreq, dinc = 0;
            int baseChance;

            var  physBonus = false;
            bool fireBonus;
            bool coldBonus;
            bool nrgyBonus;
            bool poisBonus;
            bool duraBonus;
            bool luckBonus;
            bool lreqBonus;
            bool dincBonus;

            if (item is BaseWeapon weapon)
            {
                if (!CraftResources.IsStandard(weapon.Resource))
                {
                    return(EnhanceResult.AlreadyEnhanced);
                }

                baseChance = 20;

                dura = weapon.MaxHitPoints;
                luck = weapon.Attributes.Luck;
                lreq = weapon.WeaponAttributes.LowerStatReq;
                dinc = weapon.Attributes.WeaponDamage;

                fireBonus = attributes.WeaponFireDamage > 0;
                coldBonus = attributes.WeaponColdDamage > 0;
                nrgyBonus = attributes.WeaponEnergyDamage > 0;
                poisBonus = attributes.WeaponPoisonDamage > 0;

                duraBonus = attributes.WeaponDurability > 0;
                luckBonus = attributes.WeaponLuck > 0;
                lreqBonus = attributes.WeaponLowerRequirements > 0;
                dincBonus = dinc > 0;
            }
            else
            {
                var armor = (BaseArmor)item;

                if (!CraftResources.IsStandard(armor.Resource))
                {
                    return(EnhanceResult.AlreadyEnhanced);
                }

                baseChance = 20;

                phys = armor.PhysicalResistance;
                fire = armor.FireResistance;
                cold = armor.ColdResistance;
                pois = armor.PoisonResistance;
                nrgy = armor.EnergyResistance;

                dura = armor.MaxHitPoints;
                luck = armor.Attributes.Luck;
                lreq = armor.ArmorAttributes.LowerStatReq;

                physBonus = attributes.ArmorPhysicalResist > 0;
                fireBonus = attributes.ArmorFireResist > 0;
                coldBonus = attributes.ArmorColdResist > 0;
                nrgyBonus = attributes.ArmorEnergyResist > 0;
                poisBonus = attributes.ArmorPoisonResist > 0;

                duraBonus = attributes.ArmorDurability > 0;
                luckBonus = attributes.ArmorLuck > 0;
                lreqBonus = attributes.ArmorLowerRequirements > 0;
                dincBonus = false;
            }

            var skill = from.Skills[craftSystem.MainSkill].Fixed / 10;

            if (skill >= 100)
            {
                baseChance -= (skill - 90) / 10;
            }

            var res = EnhanceResult.Success;

            if (physBonus)
            {
                CheckResult(ref res, baseChance + phys);
            }

            if (fireBonus)
            {
                CheckResult(ref res, baseChance + fire);
            }

            if (coldBonus)
            {
                CheckResult(ref res, baseChance + cold);
            }

            if (nrgyBonus)
            {
                CheckResult(ref res, baseChance + nrgy);
            }

            if (poisBonus)
            {
                CheckResult(ref res, baseChance + pois);
            }

            if (duraBonus)
            {
                CheckResult(ref res, baseChance + dura / 40);
            }

            if (luckBonus)
            {
                CheckResult(ref res, baseChance + 10 + luck / 2);
            }

            if (lreqBonus)
            {
                CheckResult(ref res, baseChance + lreq / 4);
            }

            if (dincBonus)
            {
                CheckResult(ref res, baseChance + dinc / 4);
            }

            switch (res)
            {
            case EnhanceResult.Broken:
            {
                if (!craftItem.ConsumeRes(
                        from,
                        resType,
                        craftSystem,
                        ref resHue,
                        ref maxAmount,
                        ConsumeType.Half,
                        ref resMessage
                        ))
                {
                    return(EnhanceResult.NoResources);
                }

                item.Delete();
                break;
            }

            case EnhanceResult.Success:
            {
                if (!craftItem.ConsumeRes(
                        from,
                        resType,
                        craftSystem,
                        ref resHue,
                        ref maxAmount,
                        ConsumeType.All,
                        ref resMessage
                        ))
                {
                    return(EnhanceResult.NoResources);
                }

                if (item is BaseWeapon w)
                {
                    w.Resource = resource;

                    var hue = w.GetElementalDamageHue();
                    if (hue > 0)
                    {
                        w.Hue = hue;
                    }
                }
                else
                {
                    ((BaseArmor)item).Resource = resource;
                }

                break;
            }

            case EnhanceResult.Failure:
            {
                if (!craftItem.ConsumeRes(
                        from,
                        resType,
                        craftSystem,
                        ref resHue,
                        ref maxAmount,
                        ConsumeType.Half,
                        ref resMessage
                        ))
                {
                    return(EnhanceResult.NoResources);
                }

                break;
            }
            }

            return(res);
        }
        public static EnhanceResult Invoke(Mobile from, CraftSystem craftSystem, BaseTool tool, Item item, CraftResource resource, Type resType, ref object resMessage)
        {
            if (item == null)
            {
                return(EnhanceResult.BadItem);
            }

            if (!item.IsChildOf(from.Backpack))
            {
                return(EnhanceResult.NotInBackpack);
            }

            if (!(item is BaseArmor) && !(item is BaseWeapon) && !(item is BaseOtherEquipable))
            {
                return(EnhanceResult.BadItem);
            }

            if (item is IArcaneEquip)
            {
                IArcaneEquip eq = (IArcaneEquip)item;
                if (eq.IsArcane)
                {
                    return(EnhanceResult.BadItem);
                }
            }

            if (CraftResources.IsStandard(resource))
            {
                return(EnhanceResult.BadResource);
            }

            int num = craftSystem.CanCraft(from, tool, item.GetType());

            if (num > 0)
            {
                resMessage = num;
                return(EnhanceResult.None);
            }

            CraftItem craftItem = craftSystem.CraftItems.SearchFor(item.GetType());

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

            bool allRequiredSkills = false;

            if (craftItem.GetSuccessChance(from, resType, craftSystem, false, ref allRequiredSkills) <= 0.0)
            {
                return(EnhanceResult.NoSkill);
            }

            CraftResourceInfo info = CraftResources.GetInfo(resource);

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

            CraftAttributeInfo attributes = info.AttributeInfo;

            if (attributes == null)
            {
                return(EnhanceResult.BadResource);
            }

            int resHue = 0, maxAmount = 0;

            if (!craftItem.ConsumeRes(from, resType, craftSystem, ref resHue, ref maxAmount, ConsumeType.None, ref resMessage))
            {
                return(EnhanceResult.NoResources);
            }

            if (craftSystem is DefBlacksmithy)
            {
                AncientSmithyHammer hammer = from.FindItemOnLayer(Layer.OneHanded) as AncientSmithyHammer;
                if (hammer != null)
                {
                    hammer.UsesRemaining--;
                    if (hammer.UsesRemaining < 1)
                    {
                        hammer.Delete();
                    }
                }
            }

            int baseChance = 0;

            BonusAttribute[] bonusAttrs  = null;
            BonusAttribute[] randomAttrs = null;

            if (item is BaseWeapon)
            {
                BaseWeapon weapon = (BaseWeapon)item;

                if (!CraftResources.IsStandard(weapon.Resource))
                {
                    return(EnhanceResult.AlreadyEnhanced);
                }

                baseChance = 20;

                CheckSkill(ref baseChance, from, craftSystem);

                int numOfRand = attributes.RandomAttributeCount;

                bonusAttrs  = attributes.WeaponAttributes;
                randomAttrs = BonusAttributesHelper.GetRandomAttributes(attributes.WeaponRandomAttributes, numOfRand);
            }
            else if (item is BaseArmor)
            {
                BaseArmor armor = (BaseArmor)item;

                if (!CraftResources.IsStandard(armor.Resource))
                {
                    return(EnhanceResult.AlreadyEnhanced);
                }

                baseChance = 20;

                CheckSkill(ref baseChance, from, craftSystem);

                int numOfRand = attributes.RandomAttributeCount;

                if (armor.UsesShieldAttrs)
                {
                    bonusAttrs  = attributes.ShieldAttributes;
                    randomAttrs = BonusAttributesHelper.GetRandomAttributes(attributes.ShieldRandomAttributes, numOfRand);
                }
                else
                {
                    bonusAttrs  = info.AttributeInfo.ArmorAttributes;
                    randomAttrs = BonusAttributesHelper.GetRandomAttributes(attributes.ArmorRandomAttributes, numOfRand);
                }
            }
            else if (item is BaseOtherEquipable)
            {
                BaseOtherEquipable otherEquip = (BaseOtherEquipable)item;

                if (!CraftResources.IsStandard(otherEquip.Resource))
                {
                    return(EnhanceResult.AlreadyEnhanced);
                }

                baseChance = 20;

                CheckSkill(ref baseChance, from, craftSystem);

                int numOfRand = attributes.RandomAttributeCount;

                bonusAttrs  = attributes.OtherAttributes;
                randomAttrs = BonusAttributesHelper.GetRandomAttributes(attributes.OtherRandomAttributes, numOfRand);
            }

            List <BonusAttribute> attrs = new List <BonusAttribute>();

            if (bonusAttrs != null && bonusAttrs.Length > 0)
            {
                attrs.AddRange(bonusAttrs);
            }
            if (randomAttrs != null && randomAttrs.Length > 0)
            {
                attrs.AddRange(randomAttrs);
            }

            EnhanceResult res = EnhanceResult.Success;

            TryEnhance(attrs, item, baseChance, ref res);

            switch (res)
            {
            case EnhanceResult.Broken:
            {
                if (!craftItem.ConsumeRes(from, resType, craftSystem, ref resHue, ref maxAmount, ConsumeType.Half, ref resMessage))
                {
                    return(EnhanceResult.NoResources);
                }

                item.Delete();
                break;
            }

            case EnhanceResult.Success:
            {
                if (!craftItem.ConsumeRes(from, resType, craftSystem, ref resHue, ref maxAmount, ConsumeType.All, ref resMessage))
                {
                    return(EnhanceResult.NoResources);
                }

                if (item is BaseWeapon)
                {
                    BaseWeapon w = (BaseWeapon)item;

                    w.RandomAttributes = randomAttrs;

                    w.Resource = resource;

                    w.Hue = w.GetElementalDamageHue(w.Hue);
                }
                else if (item is BaseArmor)
                {
                    BaseArmor ar = (BaseArmor)item;

                    ar.RandomAttributes = randomAttrs;

                    ((BaseArmor)item).Resource = resource;
                }
                else if (item is BaseOtherEquipable)                            //Sanity
                {
                    BaseOtherEquipable otherEquip = (BaseOtherEquipable)item;

                    otherEquip.RandomAttributes = randomAttrs;

                    ((BaseOtherEquipable)item).Resource = resource;
                }

                break;
            }

            case EnhanceResult.Failure:
            {
                if (!craftItem.ConsumeRes(from, resType, craftSystem, ref resHue, ref maxAmount, ConsumeType.Half, ref resMessage))
                {
                    return(EnhanceResult.NoResources);
                }

                break;
            }
            }

            return(res);
        }
        public static EnhanceResult Invoke( Mobile from, CraftSystem craftSystem, BaseTool tool, Item item, CraftResource resource, Type resType, ref object resMessage )
        {
            if ( item == null )
                return EnhanceResult.BadItem;

            if ( !item.IsChildOf( from.Backpack ) )
                return EnhanceResult.NotInBackpack;

            if ( !(item is BaseArmor) && !(item is BaseWeapon) && !(item is BaseOtherEquipable) )
                return EnhanceResult.BadItem;

            if ( item is IArcaneEquip )
            {
                IArcaneEquip eq = (IArcaneEquip)item;
                if ( eq.IsArcane )
                    return EnhanceResult.BadItem;
            }

            if ( CraftResources.IsStandard( resource ) )
                return EnhanceResult.BadResource;

            int num = craftSystem.CanCraft( from, tool, item.GetType() );

            if ( num > 0 )
            {
                resMessage = num;
                return EnhanceResult.None;
            }

            CraftItem craftItem = craftSystem.CraftItems.SearchFor( item.GetType() );

            if ( craftItem == null || craftItem.Resources.Count == 0 )
                return EnhanceResult.BadItem;

            bool allRequiredSkills = false;
            if( craftItem.GetSuccessChance( from, resType, craftSystem, false, ref allRequiredSkills ) <= 0.0 )
                return EnhanceResult.NoSkill;

            CraftResourceInfo info = CraftResources.GetInfo( resource );

            if ( info == null || info.ResourceTypes.Length == 0 )
                return EnhanceResult.BadResource;

            CraftAttributeInfo attributes = info.AttributeInfo;

            if ( attributes == null )
                return EnhanceResult.BadResource;

            int resHue = 0, maxAmount = 0;

            if ( !craftItem.ConsumeRes( from, resType, craftSystem, ref resHue, ref maxAmount, ConsumeType.None, ref resMessage ) )
                return EnhanceResult.NoResources;

            if ( craftSystem is DefBlacksmithy )
            {
                AncientSmithyHammer hammer = from.FindItemOnLayer( Layer.OneHanded ) as AncientSmithyHammer;
                if ( hammer != null )
                {
                    hammer.UsesRemaining--;
                    if ( hammer.UsesRemaining < 1 )
                        hammer.Delete();
                }
            }

            int baseChance = 0;

            BonusAttribute[] bonusAttrs = null;
            BonusAttribute[] randomAttrs = null;

            if ( item is BaseWeapon )
            {
                BaseWeapon weapon = (BaseWeapon)item;

                if ( !CraftResources.IsStandard( weapon.Resource ) )
                    return EnhanceResult.AlreadyEnhanced;

                baseChance = 18; // Silver: used to be 20

                CheckSkill( ref baseChance, from, craftSystem );

                int numOfRand = attributes.RandomAttributeCount;

                bonusAttrs = attributes.WeaponAttributes;
                randomAttrs = BonusAttributesHelper.GetRandomAttributes( attributes.WeaponRandomAttributes, numOfRand );
            }
            else if ( item is BaseArmor )
            {
                BaseArmor armor = (BaseArmor)item;

                if ( !CraftResources.IsStandard( armor.Resource ) )
                    return EnhanceResult.AlreadyEnhanced;

                baseChance = 18; // Silver: used to be 20

                CheckSkill( ref baseChance, from, craftSystem );

                int numOfRand = attributes.RandomAttributeCount;

                if ( armor.UsesShieldAttrs )
                {
                    bonusAttrs = attributes.ShieldAttributes;
                    randomAttrs = BonusAttributesHelper.GetRandomAttributes( attributes.ShieldRandomAttributes, numOfRand );
                }
                else
                {
                    bonusAttrs = info.AttributeInfo.ArmorAttributes;
                    randomAttrs = BonusAttributesHelper.GetRandomAttributes( attributes.ArmorRandomAttributes, numOfRand );
                }
            }
            else if ( item is BaseOtherEquipable )
            {
                BaseOtherEquipable otherEquip = (BaseOtherEquipable)item;

                if ( !CraftResources.IsStandard( otherEquip.Resource ) )
                    return EnhanceResult.AlreadyEnhanced;

                baseChance = 18; // Kamron: used to be 20

                CheckSkill( ref baseChance, from, craftSystem );

                int numOfRand = attributes.RandomAttributeCount;

                bonusAttrs = attributes.OtherAttributes;
                randomAttrs = BonusAttributesHelper.GetRandomAttributes( attributes.OtherRandomAttributes, numOfRand );
            }

            List<BonusAttribute> attrs = new List<BonusAttribute>();
            if ( bonusAttrs != null && bonusAttrs.Length > 0 )
                attrs.AddRange( bonusAttrs );
            if ( randomAttrs != null && randomAttrs.Length > 0 )
                attrs.AddRange( randomAttrs );

            EnhanceResult res = EnhanceResult.Success;

            TryEnhance( attrs, item, baseChance, ref res );

            switch ( res )
            {
                case EnhanceResult.Broken:
                {
                    if ( !craftItem.ConsumeRes( from, resType, craftSystem, ref resHue, ref maxAmount, ConsumeType.Half, ref resMessage ) )
                        return EnhanceResult.NoResources;

                    item.Delete();
                    break;
                }
                case EnhanceResult.Success:
                {
                    if ( !craftItem.ConsumeRes( from, resType, craftSystem, ref resHue, ref maxAmount, ConsumeType.All, ref resMessage ) )
                        return EnhanceResult.NoResources;

                    if( item is BaseWeapon )
                    {
                        BaseWeapon w = (BaseWeapon)item;

                        w.RandomAttributes = randomAttrs;

                        w.Resource = resource;

                        w.Hue = w.GetElementalDamageHue( w.Hue );
                    }
                    else if( item is BaseArmor )
                    {
                        BaseArmor ar = (BaseArmor)item;

                        ar.RandomAttributes = randomAttrs;

                        ((BaseArmor)item).Resource = resource;
                    }
                    else if( item is BaseOtherEquipable )	//Sanity
                    {
                        BaseOtherEquipable otherEquip = (BaseOtherEquipable)item;

                        otherEquip.RandomAttributes = randomAttrs;

                        ((BaseOtherEquipable)item).Resource = resource;
                    }

                    break;
                }
                case EnhanceResult.Failure:
                {
                    if ( !craftItem.ConsumeRes( from, resType, craftSystem, ref resHue, ref maxAmount, ConsumeType.Half, ref resMessage ) )
                        return EnhanceResult.NoResources;

                    break;
                }
            }

            return res;
        }
Exemple #36
0
		public void Craft(Mobile from, CraftSystem craftSystem, Type typeRes, BaseTool tool)
		{
			if (from.BeginAction(typeof(CraftSystem)))
			{
				if (RequiredExpansion == Expansion.None ||
					(from.NetState != null && from.NetState.SupportsExpansion(RequiredExpansion)))
				{
					bool allRequiredSkills = true;
					double chance = GetSuccessChance(from, typeRes, craftSystem, false, ref allRequiredSkills);

					if (allRequiredSkills && chance >= 0.0)
					{
                        if (Recipe == null || !(from is PlayerMobile) || ((PlayerMobile)from).HasRecipe(Recipe))
                        {
                            if (!RequiresBasketWeaving || (from is PlayerMobile && ((PlayerMobile)from).BasketWeaving))
                            {
                                if (!RequiresMechanicalLife || (from is PlayerMobile && ((PlayerMobile)from).MechanicalLife))
                                {
                                    int badCraft = craftSystem.CanCraft(from, tool, m_Type);

                                    if (badCraft <= 0)
                                    {
                                        if (RequiresResTarget && NeedsResTarget(from, craftSystem))
                                        {
                                            from.Target = new ChooseResTarget(from, this, craftSystem, typeRes, tool);
                                            from.SendMessage("Choose the resource you would like to use.");
                                            return;
                                        }

                                        int resHue = 0;
                                        int maxAmount = 0;
                                        object message = null;

                                        if (ConsumeRes(from, typeRes, craftSystem, ref resHue, ref maxAmount, ConsumeType.None, ref message))
                                        {
                                            message = null;

                                            if (ConsumeAttributes(from, ref message, false))
                                            {
                                                CraftContext context = craftSystem.GetContext(from);

                                                if (context != null)
                                                {
                                                    context.OnMade(this);
                                                }

                                                int iMin = craftSystem.MinCraftEffect;
                                                int iMax = (craftSystem.MaxCraftEffect - iMin) + 1;
                                                int iRandom = Utility.Random(iMax);
                                                iRandom += iMin + 1;
                                                new InternalTimer(from, craftSystem, this, typeRes, tool, iRandom).Start();
                                                return;
                                            }
                                            else
                                            {
                                                from.EndAction(typeof(CraftSystem));
                                                from.SendGump(new CraftGump(from, craftSystem, tool, message));
                                            }
                                        }
                                        else
                                        {
                                            from.EndAction(typeof(CraftSystem));
                                            from.SendGump(new CraftGump(from, craftSystem, tool, message));
                                        }
                                    }
                                    else
                                    {
                                        from.EndAction(typeof(CraftSystem));
                                        from.SendGump(new CraftGump(from, craftSystem, tool, badCraft));
                                    }
                                }
                                else
                                {
                                    from.EndAction(typeof(CraftSystem));
                                    from.SendGump(new CraftGump(from, craftSystem, tool, 1113034)); // You haven't read the Mechanical Life Manual. Talking to Sutek might help!
                                }
                            }
                            else
                            {
                                from.EndAction(typeof(CraftSystem));
                                from.SendGump(new CraftGump(from, craftSystem, tool, 1112253)); // You haven't learned basket weaving. Perhaps studying a book would help!
                            }
                        }
                        else
                        {
                            from.EndAction(typeof(CraftSystem));
                            from.SendGump(new CraftGump(from, craftSystem, tool, 1072847)); // You must learn that recipe from a scroll.
                        }
					}
					else
					{
						from.EndAction(typeof(CraftSystem));
						from.SendGump(new CraftGump(from, craftSystem, tool, 1044153));
						// You don't have the required skills to attempt this item.
					}
				}
				else
				{
					from.EndAction(typeof(CraftSystem));
					from.SendGump(new CraftGump(from, craftSystem, tool, RequiredExpansionMessage(RequiredExpansion)));
						//The {0} expansion is required to attempt this item.
				}
			}
			else
			{
				from.SendLocalizedMessage(500119); // You must wait to perform another action
			}

            AutoCraftTimer.EndTimer(from);
		}
Exemple #37
0
        public void CompleteCraft(int quality, bool makersMark, Mobile from, CraftSystem craftSystem, Type typeRes, BaseTool tool, CustomCraft customCraft)
        {
            int badCraft = craftSystem.CanCraft(from, tool, m_Type);

            if (badCraft > 0)
            {
                if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
                {
                    from.SendGump(new CraftGump(from, craftSystem, tool, badCraft));
                }
                else
                {
                    from.SendLocalizedMessage(badCraft);
                }

                return;
            }

            int    checkResHue = 0, checkMaxAmount = 0;
            object checkMessage = null;

            // Not enough resource to craft it
            if (!ConsumeRes(from, typeRes, craftSystem, ref checkResHue, ref checkMaxAmount, ConsumeType.None, ref checkMessage))
            {
                if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
                {
                    from.SendGump(new CraftGump(from, craftSystem, tool, checkMessage));
                }
                else if (checkMessage is int && (int)checkMessage > 0)
                {
                    from.SendLocalizedMessage((int)checkMessage);
                }
                else if (checkMessage is string)
                {
                    from.SendMessage((string)checkMessage);
                }

                return;
            }
            else if (!ConsumeAttributes(from, ref checkMessage, false))
            {
                if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
                {
                    from.SendGump(new CraftGump(from, craftSystem, tool, checkMessage));
                }
                else if (checkMessage is int && (int)checkMessage > 0)
                {
                    from.SendLocalizedMessage((int)checkMessage);
                }
                else if (checkMessage is string)
                {
                    from.SendMessage((string)checkMessage);
                }

                return;
            }

            bool toolBroken = false;

            int ignored    = 1;
            int endquality = 1;

            bool allRequiredSkills = true;

            if (CheckSkills(from, typeRes, craftSystem, ref ignored, ref allRequiredSkills))
            {
                // Resource
                int resHue    = 0;
                int maxAmount = 0;

                object message = null;

                // Not enough resource to craft it
                if (!ConsumeRes(from, typeRes, craftSystem, ref resHue, ref maxAmount, ConsumeType.All, ref message))
                {
                    if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
                    {
                        from.SendGump(new CraftGump(from, craftSystem, tool, message));
                    }
                    else if (message is int && (int)message > 0)
                    {
                        from.SendLocalizedMessage((int)message);
                    }
                    else if (message is string)
                    {
                        from.SendMessage((string)message);
                    }

                    return;
                }
                else if (!ConsumeAttributes(from, ref message, true))
                {
                    if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
                    {
                        from.SendGump(new CraftGump(from, craftSystem, tool, message));
                    }
                    else if (message is int && (int)message > 0)
                    {
                        from.SendLocalizedMessage((int)message);
                    }
                    else if (message is string)
                    {
                        from.SendMessage((string)message);
                    }

                    return;
                }

                tool.UsesRemaining--;

                if (craftSystem is DefBlacksmithy)
                {
                    AncientSmithyHammer hammer = from.FindItemOnLayer(Layer.OneHanded) as AncientSmithyHammer;
                    if (hammer != null && hammer != tool)
                    {
                        hammer.UsesRemaining--;
                        if (hammer.UsesRemaining < 1)
                        {
                            hammer.Delete();
                        }
                    }
                }

                if (tool.UsesRemaining < 1 && tool.BreakOnDepletion)
                {
                    toolBroken = true;
                }

                if (toolBroken)
                {
                    tool.Delete();
                }

                int num = 0;

                Item item;
                if (customCraft != null)
                {
                    item = customCraft.CompleteCraft(out num);
                }
                else if (typeof(MapItem).IsAssignableFrom(ItemType) && from.Map != Map.Felucca)
                {
                    item = new IndecipherableMap();
                    from.SendLocalizedMessage(1070800); // The map you create becomes mysteriously indecipherable.
                }
                else
                {
                    item = Activator.CreateInstance(ItemType) as Item;
                }

                if (item != null)
                {
                    if (item is ICraftable)
                    {
                        endquality = ((ICraftable)item).OnCraft(quality, makersMark, from, craftSystem, typeRes, tool, this, resHue);
                    }
                    else if (item.Hue == 0)
                    {
                        item.Hue = resHue;
                    }

                    if (maxAmount > 0)
                    {
                        if (!item.Stackable && item is IUsesRemaining)
                        {
                            ((IUsesRemaining)item).UsesRemaining *= maxAmount;
                        }
                        else
                        {
                            item.Amount = maxAmount;
                        }
                    }

                    if (from is Player)
                    {
                        Player    p  = from as Player;
                        Craftsman cm = Perk.GetByType <Craftsman>(p);

                        if (cm != null && cm.Craftsmanship())
                        {
                            if (item is BaseArmor)
                            {
                                ((BaseArmor)item).MaxHitPoints += Utility.RandomMinMax(25, 30);
                                ((BaseArmor)item).HitPoints     = ((BaseWeapon)item).MaxHitPoints;
                            }

                            if (item is BaseWeapon)
                            {
                                ((BaseWeapon)item).MaxHitPoints += Utility.RandomMinMax(25, 30);
                                ((BaseWeapon)item).HitPoints     = ((BaseWeapon)item).MaxHitPoints;
                            }

                            if (item is BaseClothing)
                            {
                                ((BaseClothing)item).MaxHitPoints += Utility.RandomMinMax(25, 30);
                                ((BaseClothing)item).HitPoints     = ((BaseClothing)item).MaxHitPoints;
                            }
                        }
                    }

                    from.AddToBackpack(item);

                    if (from.AccessLevel > AccessLevel.Player)
                    {
                        Commands.CommandLogging.WriteLine(from, "Crafting {0} with craft system {1}", Commands.CommandLogging.Format(item), craftSystem.GetType().Name);
                    }

                    from.PlaySound(0x57);
                }

                if (num == 0)
                {
                    num = craftSystem.PlayEndingEffect(from, false, true, toolBroken, endquality, makersMark, this);
                }

                if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
                {
                    from.SendGump(new CraftGump(from, craftSystem, tool, num));
                }
                else if (num > 0)
                {
                    from.SendLocalizedMessage(num);
                }

                EventDispatcher.InvokeItemCraft(new ItemCraftEventArgs((Player)from, true, this, craftSystem));
            }
            else if (!allRequiredSkills)
            {
                if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
                {
                    from.SendGump(new CraftGump(from, craftSystem, tool, 1044153));
                }
                else
                {
                    from.SendLocalizedMessage(1044153); // You don't have the required skills to attempt this item.
                }
            }
            else
            {
                ConsumeType consumeType = (UseAllRes ? ConsumeType.Half : ConsumeType.All);
                int         resHue      = 0;
                int         maxAmount   = 0;

                object message = null;

                // Not enough resource to craft it
                if (!ConsumeRes(from, typeRes, craftSystem, ref resHue, ref maxAmount, consumeType, ref message, true))
                {
                    if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
                    {
                        from.SendGump(new CraftGump(from, craftSystem, tool, message));
                    }
                    else if (message is int && (int)message > 0)
                    {
                        from.SendLocalizedMessage((int)message);
                    }
                    else if (message is string)
                    {
                        from.SendMessage((string)message);
                    }

                    return;
                }

                tool.UsesRemaining--;

                if (tool.UsesRemaining < 1 && tool.BreakOnDepletion)
                {
                    toolBroken = true;
                }

                if (toolBroken)
                {
                    tool.Delete();
                }

                // SkillCheck failed.
                int num = craftSystem.PlayEndingEffect(from, true, true, toolBroken, endquality, false, this);

                if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
                {
                    from.SendGump(new CraftGump(from, craftSystem, tool, num));
                }
                else if (num > 0)
                {
                    from.SendLocalizedMessage(num);
                }

                EventDispatcher.InvokeItemCraft(new ItemCraftEventArgs((Player)from, false, this, craftSystem));
            }
        }
Exemple #38
0
            protected override void OnTick()
            {
                m_iCount++;

                m_From.DisruptiveAction();

                if (m_iCount < m_iCountMax)
                {
                    m_CraftSystem.PlayCraftEffect(m_From);
                }
                else
                {
                    m_From.EndAction(typeof(CraftSystem));

                    int badCraft = m_CraftSystem.CanCraft(m_From, m_Tool, m_CraftItem.m_Type);

                    if (badCraft > 0)
                    {
                        if (m_Tool != null && !m_Tool.Deleted && m_Tool.UsesRemaining > 0)
                        {
                            m_From.SendGump(new CraftGump(m_From, m_CraftSystem, m_Tool, badCraft));
                        }
                        else
                        {
                            m_From.SendLocalizedMessage(badCraft);
                        }

                        return;
                    }

                    int  quality           = 1;
                    bool allRequiredSkills = true;

                    m_CraftItem.CheckSkills(m_From, m_TypeRes, m_CraftSystem, ref quality, ref allRequiredSkills, false);

                    CraftContext context = m_CraftSystem.GetContext(m_From);

                    if (context == null)
                    {
                        return;
                    }

                    if (typeof(CustomCraft).IsAssignableFrom(m_CraftItem.ItemType))
                    {
                        CustomCraft cc = null;

                        try { cc = Activator.CreateInstance(m_CraftItem.ItemType, new object[] { m_From, m_CraftItem, m_CraftSystem, m_TypeRes, m_Tool, quality }) as CustomCraft; }
                        catch { }

                        if (cc != null)
                        {
                            cc.EndCraftAction();
                        }

                        return;
                    }

                    bool makersMark = false;

                    if (quality == 2 && m_From.Skills[m_CraftSystem.MainSkill].Base >= 100.0)
                    {
                        makersMark = m_CraftItem.IsMarkable(m_CraftItem.ItemType);
                    }

                    if (makersMark && context.MarkOption == CraftMarkOption.PromptForMark)
                    {
                        m_From.SendGump(new QueryMakersMarkGump(quality, m_From, m_CraftItem, m_CraftSystem, m_TypeRes, m_Tool));
                    }
                    else
                    {
                        if (context.MarkOption == CraftMarkOption.DoNotMark)
                        {
                            makersMark = false;
                        }

                        m_CraftItem.CompleteCraft(quality, makersMark, m_From, m_CraftSystem, m_TypeRes, m_Tool, null);
                    }
                }
            }
Exemple #39
0
            protected override void OnTarget(Mobile from, object targeted)
            {
                bool usingDeed = (m_Deed != null) || (m_Addon != null);
                bool toDelete  = false;
                int  number;

                double value = 0;

                if (m_Deed != null)
                {
                    value = m_Deed.SkillLevel;
                }
                else if (m_Addon != null)
                {
                    var tool = m_Addon.Tools.Find(x => x.System == m_CraftSystem);

                    if (tool.Charges == 0)
                    {
                        from.SendLocalizedMessage(1019073);// This item is out of charges.
                        // m_Addon.Using = false;
                        m_Addon.User = null;
                        return;
                    }

                    value = tool.SkillValue;
                }
                else
                {
                    value = from.Skills[m_CraftSystem.MainSkill].Base;
                }

                if (m_CraftSystem is DefTinkering && targeted is IRepairableMobile)
                {
                    if (TryRepairMobile(from, (IRepairableMobile)targeted, usingDeed, out toDelete))
                    {
                        number = 1044279; // You repair the item.

                        m_CraftSystem.OnRepair(from, m_Tool, m_Deed, m_Addon, (IRepairableMobile)targeted);
                    }
                    else
                    {
                        number = 500426; // You can't repair that.
                    }
                }
                else if (targeted is Item)
                {
                    if (from.InRange(((Item)targeted).GetWorldLocation(), 2))
                    {
                        if (!CheckDeed(from))
                        {
                            if (m_Addon != null)
                            {
                                // m_Addon.Using = false;
                                m_Addon.User = null;
                            }

                            return;
                        }

                        if (!AllowsRepair(targeted, m_CraftSystem))
                        {
                            from.SendLocalizedMessage(500426); // You can't repair that.

                            if (m_Addon != null)
                            {
                                // m_Addon.Using = false;
                                m_Addon.User = null;
                            }

                            return;
                        }

                        if (m_CraftSystem.CanCraft(from, m_Tool, targeted.GetType()) == 1044267)
                        {
                            number = 1044282; // You must be near a forge and and anvil to repair items. * Yes, there are two and's *
                        }
                        else if (!usingDeed && m_CraftSystem is DefTinkering && targeted is BrokenAutomatonHead)
                        {
                            if (((BrokenAutomatonHead)targeted).TryRepair(from))
                            {
                                number = 1044279; // You repair the item.
                            }
                            else
                            {
                                number = 1044280; // You fail to repair the item.
                            }
                        }
                        else if (targeted is BaseWeapon weapon)
                        {
                            SkillName skill    = m_CraftSystem.MainSkill;
                            int       toWeaken = 0;

                            if (Core.AOS)
                            {
                                toWeaken = 1;
                            }
                            else if (skill != SkillName.Tailoring)
                            {
                                double skillLevel = value;

                                if (skillLevel >= 90.0)
                                {
                                    toWeaken = 1;
                                }
                                else if (skillLevel >= 70.0)
                                {
                                    toWeaken = 2;
                                }
                                else
                                {
                                    toWeaken = 3;
                                }
                            }

                            if (m_CraftSystem.CraftItems.SearchForSubclass(weapon.GetType()) == null && !CheckSpecial(weapon))
                            {
                                number = (usingDeed) ? 1061136 : 1044277; // That item cannot be repaired. // You cannot repair that item with this type of repair contract.
                            }
                            else if (!weapon.IsChildOf(from.Backpack) && (!Core.ML || weapon.Parent != from))
                            {
                                number = 1044275; // The item must be in your backpack to repair it.
                            }
                            else if (!Core.AOS && weapon.PoisonCharges != 0)
                            {
                                number = 1005012; // You cannot repair an item while a caustic substance is on it.
                            }
                            else if (weapon.MaxHitPoints <= 0 || weapon.HitPoints == weapon.MaxHitPoints)
                            {
                                number = 1044281; // That item is in full repair
                            }
                            else if (weapon.MaxHitPoints <= toWeaken)
                            {
                                number = 1044278; // That item has been repaired many times, and will break if repairs are attempted again.
                            }
                            else if (weapon.NegativeAttributes.NoRepair > 0)
                            {
                                number = 1044277; // That item cannot be repaired.
                            }
                            else
                            {
                                if (CheckWeaken(from, skill, weapon.HitPoints, weapon.MaxHitPoints))
                                {
                                    weapon.MaxHitPoints -= toWeaken;
                                    weapon.HitPoints     = Math.Max(0, weapon.HitPoints - toWeaken);
                                }

                                if (CheckRepairDifficulty(from, skill, weapon.HitPoints, weapon.MaxHitPoints))
                                {
                                    number = 1044279; // You repair the item.
                                    m_CraftSystem.PlayCraftEffect(from);
                                    weapon.HitPoints = weapon.MaxHitPoints;

                                    m_CraftSystem.OnRepair(from, m_Tool, m_Deed, m_Addon, weapon);
                                }
                                else
                                {
                                    number = (usingDeed) ? 1061137 : 1044280; // You fail to repair the item. [And the contract is destroyed]
                                    m_CraftSystem.PlayCraftEffect(from);
                                }

                                toDelete = true;
                            }
                        }
                        else if (targeted is BaseArmor armor)
                        {
                            SkillName skill    = m_CraftSystem.MainSkill;
                            int       toWeaken = 0;

                            if (Core.AOS)
                            {
                                toWeaken = 1;
                            }
                            else if (skill != SkillName.Tailoring)
                            {
                                double skillLevel = value;

                                if (skillLevel >= 90.0)
                                {
                                    toWeaken = 1;
                                }
                                else if (skillLevel >= 70.0)
                                {
                                    toWeaken = 2;
                                }
                                else
                                {
                                    toWeaken = 3;
                                }
                            }

                            if (m_CraftSystem.CraftItems.SearchForSubclass(armor.GetType()) == null && !CheckSpecial(armor))
                            {
                                number = (usingDeed) ? 1061136 : 1044277; // That item cannot be repaired. // You cannot repair that item with this type of repair contract.
                            }
                            else if (!armor.IsChildOf(from.Backpack) && (!Core.ML || armor.Parent != from))
                            {
                                number = 1044275; // The item must be in your backpack to repair it.
                            }
                            else if (armor.MaxHitPoints <= 0 || armor.HitPoints == armor.MaxHitPoints)
                            {
                                number = 1044281; // That item is in full repair
                            }
                            else if (armor.MaxHitPoints <= toWeaken)
                            {
                                number = 1044278; // That item has been repaired many times, and will break if repairs are attempted again.
                            }
                            else if (armor.NegativeAttributes.NoRepair > 0)
                            {
                                number = 1044277; // That item cannot be repaired.
                            }
                            else
                            {
                                if (CheckWeaken(from, skill, armor.HitPoints, armor.MaxHitPoints))
                                {
                                    armor.MaxHitPoints -= toWeaken;
                                    armor.HitPoints     = Math.Max(0, armor.HitPoints - toWeaken);
                                }

                                if (CheckRepairDifficulty(from, skill, armor.HitPoints, armor.MaxHitPoints))
                                {
                                    number = 1044279; // You repair the item.
                                    m_CraftSystem.PlayCraftEffect(from);
                                    armor.HitPoints = armor.MaxHitPoints;

                                    m_CraftSystem.OnRepair(from, m_Tool, m_Deed, m_Addon, armor);
                                }
                                else
                                {
                                    number = (usingDeed) ? 1061137 : 1044280; // You fail to repair the item. [And the contract is destroyed]
                                    m_CraftSystem.PlayCraftEffect(from);
                                }

                                toDelete = true;
                            }
                        }
                        else if (targeted is BaseJewel jewel)
                        {
                            SkillName skill    = m_CraftSystem.MainSkill;
                            int       toWeaken = 0;

                            if (Core.AOS)
                            {
                                toWeaken = 1;
                            }
                            else if (skill != SkillName.Tailoring)
                            {
                                double skillLevel = value;

                                if (skillLevel >= 90.0)
                                {
                                    toWeaken = 1;
                                }
                                else if (skillLevel >= 70.0)
                                {
                                    toWeaken = 2;
                                }
                                else
                                {
                                    toWeaken = 3;
                                }
                            }

                            if (m_CraftSystem.CraftItems.SearchForSubclass(jewel.GetType()) == null && !CheckSpecial(jewel))
                            {
                                number = (usingDeed) ? 1061136 : 1044277; // That item cannot be repaired. // You cannot repair that item with this type of repair contract.
                            }
                            else if (!jewel.IsChildOf(from.Backpack))
                            {
                                number = 1044275; // The item must be in your backpack to repair it.
                            }
                            else if (jewel.MaxHitPoints <= 0 || jewel.HitPoints == jewel.MaxHitPoints)
                            {
                                number = 1044281; // That item is in full repair
                            }
                            else if (jewel.MaxHitPoints <= toWeaken)
                            {
                                number = 1044278; // That item has been repaired many times, and will break if repairs are attempted again.
                            }
                            else if (jewel.NegativeAttributes.NoRepair > 0)
                            {
                                number = 1044277; // That item cannot be repaired.
                            }
                            else
                            {
                                if (CheckWeaken(from, skill, jewel.HitPoints, jewel.MaxHitPoints))
                                {
                                    jewel.MaxHitPoints -= toWeaken;
                                    jewel.HitPoints     = Math.Max(0, jewel.HitPoints - toWeaken);
                                }

                                if (CheckRepairDifficulty(from, skill, jewel.HitPoints, jewel.MaxHitPoints))
                                {
                                    number = 1044279; // You repair the item.
                                    m_CraftSystem.PlayCraftEffect(from);
                                    jewel.HitPoints = jewel.MaxHitPoints;

                                    m_CraftSystem.OnRepair(from, m_Tool, m_Deed, m_Addon, jewel);
                                }
                                else
                                {
                                    number = (usingDeed) ? 1061137 : 1044280; // You fail to repair the item. [And the contract is destroyed]
                                    m_CraftSystem.PlayCraftEffect(from);
                                }

                                toDelete = true;
                            }
                        }
                        else if (targeted is BaseClothing clothing)
                        {
                            SkillName skill    = m_CraftSystem.MainSkill;
                            int       toWeaken = 0;

                            if (Core.AOS)
                            {
                                toWeaken = 1;
                            }
                            else if (skill != SkillName.Tailoring)
                            {
                                double skillLevel = value;

                                if (skillLevel >= 90.0)
                                {
                                    toWeaken = 1;
                                }
                                else if (skillLevel >= 70.0)
                                {
                                    toWeaken = 2;
                                }
                                else
                                {
                                    toWeaken = 3;
                                }
                            }

                            if (m_CraftSystem.CraftItems.SearchForSubclass(clothing.GetType()) == null && !CheckSpecial(clothing))
                            {
                                number = (usingDeed) ? 1061136 : 1044277; // That item cannot be repaired. // You cannot repair that item with this type of repair contract.
                            }
                            else if (!clothing.IsChildOf(from.Backpack) && (!Core.ML || clothing.Parent != from))
                            {
                                number = 1044275; // The item must be in your backpack to repair it.
                            }
                            else if (clothing.MaxHitPoints <= 0 || clothing.HitPoints == clothing.MaxHitPoints)
                            {
                                number = 1044281; // That item is in full repair
                            }
                            else if (clothing.MaxHitPoints <= toWeaken)
                            {
                                number = 1044278;                              // That item has been repaired many times, and will break if repairs are attempted again.
                            }
                            else if (clothing.NegativeAttributes.NoRepair > 0) // quick fix
                            {
                                number = 1044277;                              // That item cannot be repaired.
                            }
                            else
                            {
                                if (CheckWeaken(from, skill, clothing.HitPoints, clothing.MaxHitPoints))
                                {
                                    clothing.MaxHitPoints -= toWeaken;
                                    clothing.HitPoints     = Math.Max(0, clothing.HitPoints - toWeaken);
                                }

                                if (CheckRepairDifficulty(from, skill, clothing.HitPoints, clothing.MaxHitPoints))
                                {
                                    number = 1044279; // You repair the item.
                                    m_CraftSystem.PlayCraftEffect(from);
                                    clothing.HitPoints = clothing.MaxHitPoints;

                                    m_CraftSystem.OnRepair(from, m_Tool, m_Deed, m_Addon, clothing);
                                }
                                else
                                {
                                    number = (usingDeed) ? 1061137 : 1044280; // You fail to repair the item. [And the contract is destroyed]
                                    m_CraftSystem.PlayCraftEffect(from);
                                }

                                toDelete = true;
                            }
                        }
                        else if (targeted is BaseTalisman talisman)
                        {
                            SkillName skill    = m_CraftSystem.MainSkill;
                            int       toWeaken = 0;

                            if (Core.AOS)
                            {
                                toWeaken = 1;
                            }
                            else if (skill != SkillName.Tailoring)
                            {
                                double skillLevel = value;

                                if (skillLevel >= 90.0)
                                {
                                    toWeaken = 1;
                                }
                                else if (skillLevel >= 70.0)
                                {
                                    toWeaken = 2;
                                }
                                else
                                {
                                    toWeaken = 3;
                                }
                            }

                            if (!(m_CraftSystem is DefTinkering))
                            {
                                number = (usingDeed) ? 1061136 : 1044277; // That item cannot be repaired. // You cannot repair that item with this type of repair contract.
                            }
                            else if (!talisman.IsChildOf(from.Backpack) && (!Core.ML || talisman.Parent != from))
                            {
                                number = 1044275; // The item must be in your backpack to repair it.
                            }
                            else if (talisman.MaxHitPoints <= 0 || talisman.HitPoints == talisman.MaxHitPoints)
                            {
                                number = 1044281; // That item is in full repair
                            }
                            else if (talisman.MaxHitPoints <= toWeaken)
                            {
                                number = 1044278;         // That item has been repaired many times, and will break if repairs are attempted again.
                            }
                            else if (!talisman.CanRepair) // quick fix
                            {
                                number = 1044277;         // That item cannot be repaired.
                            }
                            else
                            {
                                if (CheckWeaken(from, skill, talisman.HitPoints, talisman.MaxHitPoints))
                                {
                                    talisman.MaxHitPoints -= toWeaken;
                                    talisman.HitPoints     = Math.Max(0, talisman.HitPoints - toWeaken);
                                }

                                if (CheckRepairDifficulty(from, skill, talisman.HitPoints, talisman.MaxHitPoints))
                                {
                                    number = 1044279; // You repair the item.
                                    m_CraftSystem.PlayCraftEffect(from);
                                    talisman.HitPoints = talisman.MaxHitPoints;

                                    m_CraftSystem.OnRepair(from, m_Tool, m_Deed, m_Addon, talisman);
                                }
                                else
                                {
                                    number = (usingDeed) ? 1061137 : 1044280; // You fail to repair the item. [And the contract is destroyed]
                                    m_CraftSystem.PlayCraftEffect(from);
                                }

                                toDelete = true;
                            }
                        }
                        else if (targeted is BlankScroll)
                        {
                            if (!usingDeed)
                            {
                                SkillName skill = m_CraftSystem.MainSkill;

                                if (from.Skills[skill].Value >= 50.0)
                                {
                                    ((BlankScroll)targeted).Consume(1);
                                    RepairDeed deed = new RepairDeed(RepairDeed.GetTypeFor(m_CraftSystem), from.Skills[skill].Value, from);
                                    from.AddToBackpack(deed);

                                    number = 500442; // You create the item and put it in your backpack.
                                }
                                else
                                {
                                    number = 1047005; // You must be at least apprentice level to create a repair service contract.
                                }
                            }
                            else
                            {
                                number = 1061136; // You cannot repair that item with this type of repair contract.
                            }
                        }
                        else
                        {
                            number = 500426; // You can't repair that.
                        }
                    }
                    else
                    {
                        number = 500446; // That is too far away.
                    }
                }
                else
                {
                    number = 500426; // You can't repair that.
                }

                if (!usingDeed)
                {
                    CraftContext context = m_CraftSystem.GetContext(from);
                    from.SendGump(new CraftGump(from, m_CraftSystem, m_Tool, number));
                }
                else
                {
                    if (m_Addon != null && !m_Addon.Deleted)
                    {
                        var tool = m_Addon.Tools.Find(x => x.System == m_CraftSystem);

                        tool.Charges--;

                        from.SendGump(new RepairBenchGump(from, m_Addon));

                        from.SendLocalizedMessage(number);
                    }
                    else
                    {
                        from.SendLocalizedMessage(number);

                        if (toDelete)
                        {
                            m_Deed.Delete();
                        }
                    }
                }
            }
Exemple #40
0
        public void CompleteCraft(int quality, bool makersMark, Mobile from, CraftSystem craftSystem, Type typeRes, BaseTool tool, CustomCraft customCraft)
        {
            int badCraft = craftSystem.CanCraft(from, tool, m_Type);

            if (badCraft > 0)
            {
                if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
                    from.SendGump(new CraftGump(from, craftSystem, tool, badCraft));
                else
                    from.SendLocalizedMessage(badCraft);

                return;
            }

            int checkResHue = 0, checkMaxAmount = 0;
            object checkMessage = null;

            // Not enough resource to craft it
            if (!ConsumeRes(from, typeRes, craftSystem, ref checkResHue, ref checkMaxAmount, ConsumeType.None, ref checkMessage))
            {
                if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
                    from.SendGump(new CraftGump(from, craftSystem, tool, checkMessage));
                else if (checkMessage is int && (int)checkMessage > 0)
                    from.SendLocalizedMessage((int)checkMessage);
                else if (checkMessage is string)
                    from.SendMessage((string)checkMessage);

                return;
            }
            else if (!ConsumeAttributes(from, ref checkMessage, false))
            {
                if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
                    from.SendGump(new CraftGump(from, craftSystem, tool, checkMessage));
                else if (checkMessage is int && (int)checkMessage > 0)
                    from.SendLocalizedMessage((int)checkMessage);
                else if (checkMessage is string)
                    from.SendMessage((string)checkMessage);

                return;
            }

            bool toolBroken = false;

            int ignored = 1;
            int endquality = 1;

            bool allRequiredSkills = true;

            if (CheckSkills(from, craftSystem, ref ignored, ref allRequiredSkills))
            {
                // Resource
                int resHue = 0;
                int maxAmount = 0;

                object message = null;

                // Not enough resource to craft it
                if (!ConsumeRes(from, typeRes, craftSystem, ref resHue, ref maxAmount, ConsumeType.All, ref message))
                {
                    if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
                        from.SendGump(new CraftGump(from, craftSystem, tool, message));
                    else if (message is int && (int)message > 0)
                        from.SendLocalizedMessage((int)message);
                    else if (message is string)
                        from.SendMessage((string)message);

                    return;
                }
                else if (!ConsumeAttributes(from, ref message, true))
                {
                    if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
                        from.SendGump(new CraftGump(from, craftSystem, tool, message));
                    else if (message is int && (int)message > 0)
                        from.SendLocalizedMessage((int)message);
                    else if (message is string)
                        from.SendMessage((string)message);

                    return;
                }

                tool.UsesRemaining--;

                if (tool.UsesRemaining < 1 && tool.BreakOnDepletion)
                    toolBroken = true;

                if (toolBroken)
                    tool.Delete();

                int num = 0;

                Item item;
                if (customCraft != null)
                {
                    item = customCraft.CompleteCraft(out num);
                }
                else if (typeof(MapItem).IsAssignableFrom(ItemType) && from.Map != Map.Felucca)
                {
                    item = new IndecipherableMap();
                    from.SendLocalizedMessage(1070800); // The map you create becomes mysteriously indecipherable.
                }
                else
                {
                    item = Activator.CreateInstance(ItemType) as Item;
                }

                if (item != null)
                {
                    if (item is ICraftable)
                        endquality = ((ICraftable)item).OnCraft(quality, makersMark, from, craftSystem, typeRes, tool, this, resHue);
                    else if (item.Hue == 0)
                        item.Hue = resHue;

                    if (maxAmount > 0)
                    {
                        if (!item.Stackable && item is IUsesRemaining)
                            ((IUsesRemaining)item).UsesRemaining *= maxAmount;
                        else
                            item.Amount = maxAmount;
                    }

                    from.AddToBackpack(item);

                    if (from.AccessLevel > AccessLevel.Player)
                        CommandLogging.WriteLine(from, "Crafting {0} with craft system {1}", CommandLogging.Format(item), craftSystem.GetType().Name);

                    //from.PlaySound( 0x57 );
                }

                if (num == 0)
                    num = craftSystem.PlayEndingEffect(from, false, true, toolBroken, endquality, makersMark, this);
                
                if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
                    from.SendGump(new CraftGump(from, craftSystem, tool, num));
                else if (num > 0)
                    from.SendLocalizedMessage(num);
            }
            else if (!allRequiredSkills)
            {
                if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
                    from.SendGump(new CraftGump(from, craftSystem, tool, 1044153));
                else
                    from.SendLocalizedMessage(1044153); // You don't have the required skills to attempt this item.
            }
            else
            {
                ConsumeType consumeType = (UseAllRes ? ConsumeType.Half : ConsumeType.All);
                int resHue = 0;
                int maxAmount = 0;

                object message = null;

                // Not enough resource to craft it
                if (!ConsumeRes(from, typeRes, craftSystem, ref resHue, ref maxAmount, consumeType, ref message, true))
                {
                    if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
                        from.SendGump(new CraftGump(from, craftSystem, tool, message));
                    else if (message is int && (int)message > 0)
                        from.SendLocalizedMessage((int)message);
                    else if (message is string)
                        from.SendMessage((string)message);

                    return;
                }

                tool.UsesRemaining--;

                if (tool.UsesRemaining < 1 && tool.BreakOnDepletion)
                    toolBroken = true;

                if (toolBroken)
                    tool.Delete();

                // SkillCheck failed.
                int num = craftSystem.PlayEndingEffect(from, true, true, toolBroken, endquality, false, this);

                if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
                    from.SendGump(new CraftGump(from, craftSystem, tool, num));
                else if (num > 0)
                    from.SendLocalizedMessage(num);
            }
        }
Exemple #41
0
        public void Craft( Mobile from, CraftSystem craftSystem, Type typeRes, BaseTool tool )
        {
            if ( from.BeginAction( typeof( CraftSystem ) ) )
            {
                int flags = from.NetState == null ? 0 : from.NetState.Flags;

                if( !RequiresSE || (flags & 0x10) != 0 )// SE 2D = 0x1F SE 3D = 0x11F
                {
                bool allRequiredSkills = true;
                double chance = GetSuccessChance( from, typeRes, craftSystem, false, ref allRequiredSkills );

                if ( allRequiredSkills && chance >= 0.0 )
                {
                    string badCraft = craftSystem.CanCraft( from, tool, m_Type );

                    if ( badCraft == "" )
                    {
                        int resHue = 0;
                        int maxAmount = 0;
                        object message = null;

                        if ( ConsumeRes( from, typeRes, craftSystem, ref resHue, ref maxAmount, ConsumeType.None, ref message ) )
                        {
                            message = null;

                            if ( ConsumeAttributes( from, ref message, false ) )
                            {
                                CraftContext context = craftSystem.GetContext( from );

                                if ( context != null )
                                    context.OnMade( this );

                                int iMin = craftSystem.MinCraftEffect;
                                int iMax = ( craftSystem.MaxCraftEffect - iMin ) + 1;
                                int iRandom = Utility.Random( iMax );
                                iRandom += iMin + 1;
                                new InternalTimer( from, craftSystem, this, typeRes, tool, iRandom ).Start();
                            }
                            else
                            {
                                from.EndAction( typeof( CraftSystem ) );
                                from.SendGump( new CraftGump( from, craftSystem, tool, message ) );
                            }
                        }
                        else
                        {
                            from.EndAction( typeof( CraftSystem ) );
                            from.SendGump( new CraftGump( from, craftSystem, tool, message ) );
                        }
                    }
                    else
                    {
                        from.EndAction( typeof( CraftSystem ) );
                        from.SendGump( new CraftGump( from, craftSystem, tool, badCraft ) );
                    }
                }
                else
                {
                    from.EndAction( typeof( CraftSystem ) );
                    from.SendGump( new CraftGump( from, craftSystem, tool, 1044153 ) ); // You don't have the required skills to attempt this item.
                }

                }
                else
                {
                    from.EndAction( typeof( CraftSystem ) );
                    from.SendGump( new CraftGump( from, craftSystem, tool, 1063307 ) ); //The "Samurai Empire" expansion is required to attempt this item.
                }
            }
            else
            {
                from.SendAsciiMessage( "You must wait to perform another action." );
            }
        }
Exemple #42
0
		public void CompleteCraft(int quality, bool makersMark, Mobile from, CraftSystem craftSystem, Type typeRes, BaseTool tool)
		{
			int badCraft = craftSystem.CanCraft(from, tool, m_Type);

			if (badCraft > 0)
			{
				if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
					from.SendGump(new CraftGump(from, craftSystem, tool, badCraft));
				else
					from.SendLocalizedMessage(badCraft);

				return;
			}

			int checkResHue = 0, checkMaxAmount = 0;
			object checkMessage = null;

			// Not enough resource to craft it
			if (!ConsumeRes(from, typeRes, craftSystem, ref checkResHue, ref checkMaxAmount, ConsumeType.None, ref checkMessage))
			{
				if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
					from.SendGump(new CraftGump(from, craftSystem, tool, checkMessage));
				else if (checkMessage is int && (int)checkMessage > 0)
					from.SendLocalizedMessage((int)checkMessage);
				else if (checkMessage is string)
					from.SendMessage((string)checkMessage);

				return;
			}
			else if (!ConsumeAttributes(from, ref checkMessage, false))
			{
				if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
					from.SendGump(new CraftGump(from, craftSystem, tool, checkMessage));
				else if (checkMessage is int && (int)checkMessage > 0)
					from.SendLocalizedMessage((int)checkMessage);
				else if (checkMessage is string)
					from.SendMessage((string)checkMessage);

				return;
			}

			bool toolBroken = false;
			int ignored = 1;
			int endquality = 1;
			bool allRequiredSkills = true;

			// pla, 01/04/07
			// -----------------------------------------------------------------
			// Additional checks required here to prevent skill gain exploit with special dye tubs.               
			if (craftSystem is DefAlchemy && (ItemType == typeof(SpecialDyeTub) || ItemType == typeof(SpecialDye)))
			{
				// note here that if lighten or darken was chosen, there will always be at least one special tub,
				// as it's set as a resource requirement.
				if (m_NameString == "> Darken the mix" || m_NameString == "> Lighten the mix")
				{
					// darken/lighten requires a special tub
					// Get list of all special tubs
					Item[] sdtubs = ((Container)from.Backpack).FindItemsByType(typeof(SpecialDyeTub), true);
					SpecialDyeTub sdtub;

					if (sdtubs.Length == 0)
					{
						//should be impossible as in reqs
						return;
					}
					else if (sdtubs.Length == 1)
					{
						// in this case we have just one tub.  This means we will leave skill gain and execution to the 
						// standard craft code below.  However, we need to first check if the tub can be lightened/darkened,
						// and if not then return to prevent skill gain with no resource use.
						sdtub = (SpecialDyeTub)sdtubs[0];
						if (sdtub != null)
						{
							if (m_NameString == "> Darken the mix")
							{
								if (!sdtub.CanDarken)
								{
									from.SendMessage("You attempt to darken the mix, but it will go no darker.");
									from.SendGump(new CraftGump(from, craftSystem, tool, 0));
									return;
								}
							}
							else
							{
								if (!sdtub.CanLighten)
								{
									from.SendMessage("You attempt to lighten the mix, but it will go no lighter.");
									from.SendGump(new CraftGump(from, craftSystem, tool, 0));
									return;
								}
							}
						}

					}
					else if (sdtubs.Length > 1)
					{
						// in this case we have more than one possible tub to select so we hand execution over to the target.
						//target also deals with all skill gain and failure/tool use etc.
						int resHue = 0;
						int maxAmount = 0;
						object message = null;
						from.SendMessage("Select the dye tub you wish to use for the process.");
						from.Target = new SpecialDyeTubTarget(this, typeRes, craftSystem, ref resHue, ref maxAmount, ref message, m_NameString, (m_NameString == "> Darken the mix" ? 1 : 2), tool);
						//and now return to prevent the rest of the code executing
						return;
					}
				}
				else
				{
					// Create/append dye.  This can either add to a same coloured special tub, or a fresh non-special tub.
					// So first we find all the valid tubs...
					Item[] dtubs = ((Container)from.Backpack).FindItemsByType(typeof(DyeTub), true);

					int iFound = 0;
					if (dtubs.Length > 0)
					{
						for (int i = 0; i < dtubs.Length; i++)
						{
							if (dtubs[i] is SpecialDyeTub)
							{
								// Is the same color?
								if (((SpecialDyeTub)dtubs[i]).StoredColorName == m_NameString && ((SpecialDyeTub)dtubs[i]).Uses < 100 && !((SpecialDyeTub)dtubs[i]).Prepped)
								{
									iFound++;
								}
							}
							else
							{
								iFound++;
							}
						}
					}

					if (iFound == 0)
					{
						from.SendMessage("You need a fresh dye tub or one that is not yet full and of the same color as the dye you are preparing.");
						from.SendGump(new CraftGump(from, craftSystem, tool, 0));
						return;
					}
					else if (iFound == 1)
					{
						// once again if no target is required then we just let it fall through
					}
					else if (iFound > 1)
					{
						//ok in this case we found more than one valid tub so hand execution over to the target and end
						int resHue = 0;
						int maxAmount = 0;
						object message = null;
						from.SendMessage("Select the dye tub you wish to use for the process.");
						from.Target = new SpecialDyeTubTarget(this, typeRes, craftSystem, ref resHue, ref maxAmount, ref message, m_NameString, 0, tool);
						return;
					}
				}
			} // ----------------------------------------------------------------- /

			//This check is where skill is (possibly) gained!  
			//PLA: 04/06/09 - Prevent skillgain from special tubs entirely
			if (!(craftSystem is DefAlchemy && (ItemType == typeof(SpecialDyeTub) || ItemType == typeof(SpecialDye))))
			{
				CheckSkills(from, typeRes, craftSystem, ref ignored, ref allRequiredSkills);
			}

			if (quality >= 0)
			{
				// Resource
				int resHue = 0;
				int maxAmount = 0;

				object message = null;

				ConsumeType ct = ConsumeType.All;

				// erl: if this is special dye, forget about consumption for now
				// ..
				if (craftSystem is DefAlchemy && (ItemType == typeof(SpecialDyeTub) || ItemType == typeof(SpecialDye)))
					ct = ConsumeType.None;
				// ..

				// Not enough resource to craft it				ha
				if (!ConsumeRes(from, typeRes, craftSystem, ref resHue, ref maxAmount, ct, ref message))
				{
					if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
						from.SendGump(new CraftGump(from, craftSystem, tool, message));
					else if (message is int && (int)message > 0)
						from.SendLocalizedMessage((int)message);
					else if (message is string)
						from.SendMessage((string)message);

					return;
				}

				if (!ConsumeAttributes(from, ref message, true))
				{
					if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
						from.SendGump(new CraftGump(from, craftSystem, tool, message));
					else if (message is int && (int)message > 0)
						from.SendLocalizedMessage((int)message);
					else if (message is string)
						from.SendMessage((string)message);

					return;
				}

				tool.UsesRemaining--;

				if (tool.UsesRemaining < 1)
					toolBroken = true;

				if (toolBroken)
					tool.Delete();

				// Adam: this is it. Make the item
				Item item = Activator.CreateInstance(ItemType) as Item;


				bool bTinkerTrap = false;

				if (item != null)
				{
					// Adam: mark it as PlayerCrafted
					item.PlayerCrafted = true;

					if (item is BaseWeapon)
					{
						BaseWeapon weapon = (BaseWeapon)item;
						weapon.Quality = (WeaponQuality)quality;
						endquality = quality;

						if (makersMark)
							weapon.Crafter = from;

						// Adam: one day we can obsolete and and use item.PlayerCrafted
						// erl: 10 Nov 05: that day is today!
						// weapon.PlayerConstructed = true;

						/*if ( Core.AOS )
						{
							Type resourceType = typeRes;

							if ( resourceType == null )
								resourceType = Ressources.GetAt( 0 ).ItemType;

							weapon.Resource = CraftResources.GetFromType( resourceType );

							CraftContext context = craftSystem.GetContext( from );

							if ( context != null && context.DoNotColor )
								weapon.Hue = 0;

							if ( tool is BaseRunicTool )
								((BaseRunicTool)tool).ApplyAttributesTo( weapon );

							if ( quality == 2 )
							{
								if ( weapon.Attributes.WeaponDamage > 35 )
									weapon.Attributes.WeaponDamage -= 20;
								else
									weapon.Attributes.WeaponDamage = 15;
							}
						}
						else
						*/
						if (tool is BaseRunicTool)
						{
							Type resourceType = typeRes;

							if (resourceType == null)
								resourceType = Ressources.GetAt(0).ItemType;

							CraftResource thisResource = CraftResources.GetFromType(resourceType);

							if (thisResource == ((BaseRunicTool)tool).Resource)
							{
								weapon.Resource = thisResource;

								CraftContext context = craftSystem.GetContext(from);

								if (context != null && context.DoNotColor)
									weapon.Hue = 0;

								switch (thisResource)
								{
									case CraftResource.DullCopper:
										{
											weapon.Identified = true;
											weapon.DurabilityLevel = WeaponDurabilityLevel.Durable;
											weapon.AccuracyLevel = WeaponAccuracyLevel.Accurate;
											break;
										}
									case CraftResource.ShadowIron:
										{
											weapon.Identified = true;
											weapon.DurabilityLevel = WeaponDurabilityLevel.Durable;
											weapon.DamageLevel = WeaponDamageLevel.Ruin;
											break;
										}
									case CraftResource.Copper:
										{
											weapon.Identified = true;
											weapon.DurabilityLevel = WeaponDurabilityLevel.Fortified;
											weapon.DamageLevel = WeaponDamageLevel.Ruin;
											weapon.AccuracyLevel = WeaponAccuracyLevel.Surpassingly;
											break;
										}
									case CraftResource.Bronze:
										{
											weapon.Identified = true;
											weapon.DurabilityLevel = WeaponDurabilityLevel.Fortified;
											weapon.DamageLevel = WeaponDamageLevel.Might;
											weapon.AccuracyLevel = WeaponAccuracyLevel.Surpassingly;
											break;
										}
									case CraftResource.Gold:
										{
											weapon.Identified = true;
											weapon.DurabilityLevel = WeaponDurabilityLevel.Indestructible;
											weapon.DamageLevel = WeaponDamageLevel.Force;
											weapon.AccuracyLevel = WeaponAccuracyLevel.Eminently;
											break;
										}
									case CraftResource.Agapite:
										{
											weapon.Identified = true;
											weapon.DurabilityLevel = WeaponDurabilityLevel.Indestructible;
											weapon.DamageLevel = WeaponDamageLevel.Power;
											weapon.AccuracyLevel = WeaponAccuracyLevel.Eminently;
											break;
										}
									case CraftResource.Verite:
										{
											weapon.Identified = true;
											weapon.DurabilityLevel = WeaponDurabilityLevel.Indestructible;
											weapon.DamageLevel = WeaponDamageLevel.Power;
											weapon.AccuracyLevel = WeaponAccuracyLevel.Exceedingly;
											break;
										}
									case CraftResource.Valorite:
										{
											weapon.Identified = true;
											weapon.DurabilityLevel = WeaponDurabilityLevel.Indestructible;
											weapon.DamageLevel = WeaponDamageLevel.Vanq;
											weapon.AccuracyLevel = WeaponAccuracyLevel.Supremely;
											break;
										}
								}
							}
						}
					}
					else if (item is BaseArmor)
					{
						BaseArmor armor = (BaseArmor)item;
						armor.Quality = (ArmorQuality)quality;
						endquality = quality;

						if (makersMark)
							armor.Crafter = from;

						Type resourceType = typeRes;

						if (resourceType == null)
							resourceType = Ressources.GetAt(0).ItemType;

						armor.Resource = CraftResources.GetFromType(resourceType);

						// Adam: one day we can obsolete and and use item.PlayerCrafted
						// erl: 10 Nov 05: that day is today!
						// armor.PlayerConstructed = true;

						CraftContext context = craftSystem.GetContext(from);

						if (context != null && context.DoNotColor)
							armor.Hue = 0;

						if (quality == 2)
							armor.DistributeBonuses((tool is BaseRunicTool ? 6 : 14));

						if (Core.AOS && tool is BaseRunicTool)
							((BaseRunicTool)tool).ApplyAttributesTo(armor);
					}
					else if (item is FullBookcase || item is FullBookcase2 || item is FullBookcase3)
					{
						// Does it now become a ruined bookcase? 5% chance.

						if (Utility.RandomDouble() > 0.95)
						{
							from.SendMessage("You craft the bookcase, but it is ruined.");

							item.Delete();
							item = new RuinedBookcase();
							item.Movable = true;
						}
						else
							from.SendMessage("You finish the bookcase and fill it with books.");

						// Consume single charge from scribe pen...

						Item[] spens = ((Container)from.Backpack).FindItemsByType(typeof(ScribesPen), true);

						if (--((ScribesPen)spens[0]).UsesRemaining == 0)
						{
							from.SendMessage("You have worn out your tool!");
							spens[0].Delete();
						}

					}
					else if (item is DragonBardingDeed)
					{
						DragonBardingDeed deed = (DragonBardingDeed)item;

						deed.Exceptional = (quality >= 2);
						endquality = quality;

						if (makersMark)
							deed.Crafter = from;

						Type resourceType = typeRes;

						if (resourceType == null)
							resourceType = Ressources.GetAt(0).ItemType;

						deed.Resource = CraftResources.GetFromType(resourceType);

						CraftContext context = craftSystem.GetContext(from);

						if (context != null && context.DoNotColor)
							deed.Hue = 0;
					}
					else if (item is BaseInstrument)
					{
						BaseInstrument instrument = (BaseInstrument)item;

						instrument.Quality = (InstrumentQuality)quality;
						endquality = quality;

						if (makersMark)
							instrument.Crafter = from;
					}
					else if (item is BaseJewel)
					{
						BaseJewel jewel = (BaseJewel)item;

						Type resourceType = typeRes;
						endquality = quality;

						if (resourceType == null)
							resourceType = Ressources.GetAt(0).ItemType;

						jewel.Resource = CraftResources.GetFromType(resourceType);

						if (1 < Ressources.Count)
						{
							resourceType = Ressources.GetAt(1).ItemType;

							if (resourceType == typeof(StarSapphire))
								jewel.GemType = GemType.StarSapphire;
							else if (resourceType == typeof(Emerald))
								jewel.GemType = GemType.Emerald;
							else if (resourceType == typeof(Sapphire))
								jewel.GemType = GemType.Sapphire;
							else if (resourceType == typeof(Ruby))
								jewel.GemType = GemType.Ruby;
							else if (resourceType == typeof(Citrine))
								jewel.GemType = GemType.Citrine;
							else if (resourceType == typeof(Amethyst))
								jewel.GemType = GemType.Amethyst;
							else if (resourceType == typeof(Tourmaline))
								jewel.GemType = GemType.Tourmaline;
							else if (resourceType == typeof(Amber))
								jewel.GemType = GemType.Amber;
							else if (resourceType == typeof(Diamond))
								jewel.GemType = GemType.Diamond;
						}

						if (makersMark)
							jewel.Crafter = from;

						jewel.Quality = (JewelQuality)quality;
					}
					else if (item is BaseClothing)
					{
						BaseClothing clothing = (BaseClothing)item;
						clothing.Quality = (ClothingQuality)quality;
						endquality = quality;

						if (makersMark)
							clothing.Crafter = from;

						// Adam: one day we can obsolete and and use item.PlayerCrafted
						// erl: 10 Nov 05: that day is today!
						// clothing.PlayerConstructed = true;

						if (item is BaseShoes)
						{
							BaseShoes shoes = (BaseShoes)item;

							if (shoes.Resource != CraftResource.None)
							{
								Type resourceType = typeRes;

								if (resourceType == null)
									resourceType = Ressources.GetAt(0).ItemType;

								shoes.Resource = CraftResources.GetFromType(resourceType);

								CraftContext context = craftSystem.GetContext(from);

								if (context != null && context.DoNotColor)
									shoes.Hue = 0;
							}
							else
							{
								shoes.Hue = resHue;
							}
						}
						else if ((item is BaseGloves) && (resHue == 0))
						{
							clothing.Hue = 1001;
							// Rhi: The default color for cloth gloves should be white, 
							// not the leather gloves color, which is what it will be if the hue is 0.
						}
						else
						{
							clothing.Hue = resHue;
						}

						// erl: give clothing initial hitpoint values
						// ..

						int iMax = clothing.InitMaxHits;
						int iMin = clothing.InitMinHits;

						if (clothing.Quality == ClothingQuality.Exceptional)
						{

							// Add 50% to both

							iMax = (iMax * 3) / 2; // Fixed order of precedence bug
							iMin = (iMin * 3) / 2;

							// make exceptional clothes newbied

							clothing.LootType = LootType.Newbied;
						}
						else if (clothing.Quality == ClothingQuality.Low)
						{
							// Lose 20% to both

							iMax = (iMax * 4) / 5; // Fixed order of precedence bug
							iMin = (iMin * 4) / 5;
						}

						clothing.HitPoints = clothing.MaxHitPoints = (short)Utility.RandomMinMax(iMin, iMax);

						// ..

					}
					else if (item is BaseTool || item is BaseHarvestTool && quality == 2)
					{
						endquality = quality;

						if (item is BaseTool)
							((BaseTool)item).UsesRemaining *= 3;
						else
							((BaseHarvestTool)item).UsesRemaining *= 3;
					}
					else if (item is MapItem)
					{
						((MapItem)item).CraftInit(from);
					}
					else if (item is LockableContainer)
					{
						if (from.CheckSkill(SkillName.Tinkering, -5.0, 15.0))
						{
							LockableContainer cont = (LockableContainer)item;

							from.SendLocalizedMessage(500636); // Your tinker skill was sufficient to make the item lockable.

							Key key = new Key(KeyType.Copper, Key.RandomValue());

							cont.KeyValue = key.KeyValue;
							cont.DropItem(key);
							/*
														double tinkering = from.Skills[SkillName.Tinkering].Value;
														int level = (int)(tinkering * 0.8);

														cont.RequiredSkill = level - 4;
														cont.LockLevel = level - 14;
														cont.MaxLockLevel = level + 35;

														if ( cont.LockLevel == 0 )
															cont.LockLevel = -1;
														else if ( cont.LockLevel > 95 )
															cont.LockLevel = 95;

														if ( cont.RequiredSkill > 95 )
															cont.RequiredSkill = 95;

														if ( cont.MaxLockLevel > 95 )
															cont.MaxLockLevel = 95;
							Commented out by darva to try new tinker lock strength code.*/

							double tinkering = from.Skills[SkillName.Tinkering].Value;
							int level = (int)(tinkering);
							cont.RequiredSkill = 36;
							if (level >= 65)
								cont.RequiredSkill = 76;
							if (level >= 80)
								cont.RequiredSkill = 84;
							if (level >= 90)
								cont.RequiredSkill = 92;
							if (level >= 100)
								cont.RequiredSkill = 100;
							cont.LockLevel = cont.RequiredSkill - 10;
							cont.MaxLockLevel = cont.RequiredSkill + 40;


						}
						else
						{
							from.SendLocalizedMessage(500637); // Your tinker skill was insufficient to make the item lockable.
						}
					}
					else if (item is Runebook)
					{
						int charges = 5 + quality + (int)(from.Skills[SkillName.Inscribe].Value / 30);
						endquality = quality;

						if (charges > 10)
							charges = 10;

						((Runebook)item).MaxCharges = charges;

						if (makersMark)
							((Runebook)item).Crafter = from;

						((Runebook)item).Quality = (RunebookQuality)quality;
					}
					else if (item is Bola)
					{
						Bola b = (Bola)item;
						b.Quality = (WeaponQuality)quality;
						endquality = quality;

						if (makersMark)
							b.Crafter = from;
					}
					else if (item.Hue == 0)
					{
						item.Hue = resHue;
					}

					if (maxAmount > 0)
						item.Amount = maxAmount;

					// **********************************************

					if (craftSystem is DefAlchemy && item is BasePotion)
					{
						BasePotion pot = (BasePotion)item;

						Container pack = from.Backpack;

						if (pack != null)
						{
							Item[] kegs = pack.FindItemsByType(typeof(PotionKeg), true);

							for (int i = 0; i < kegs.Length; ++i)
							{
								PotionKeg keg = kegs[i] as PotionKeg;

								if (keg == null)
									continue;

								if (keg.Held <= 0 || keg.Held >= 100)
									continue;

								if (keg.Type != pot.PotionEffect)
									continue;

								++keg.Held;
								item.Delete();
								item = new Bottle();

								endquality = -1; // signal placed in keg

								break;
							}
						}
					}
					if (craftSystem is DefAlchemy && (item is SpecialDye || item is SpecialDyeTub))
					{
						// Which special dye tub do we want to use?

						Item[] sdtubs = ((Container)from.Backpack).FindItemsByType(typeof(SpecialDyeTub), true);
						SpecialDyeTub sdtub;

						if (m_NameString == "> Darken the mix" || m_NameString == "> Lighten the mix" && sdtubs.Length > 0)
						{
							sdtub = (SpecialDyeTub)sdtubs[0];

							if (sdtubs.Length > 1)
							{
								// Pla, 04/01/07
								// This code will never be called now but left it in for sanity.
								// -----------------------------------------------------------------
								// Let the target take over from here
								//from.Target = new SpecialDyeTubTarget( this, typeRes, craftSystem, ref resHue, ref maxAmount, ref message, ref item, m_NameString, (m_NameString == "> Darken the mix" ? 1 : 2) );
								//from.SendMessage("Select the dye tub you wish to use for the process.");
							}
							else
							{
								int iConsume = 0;

								if (m_NameString == "> Darken the mix")
								{
									if (sdtub.DarkenMix())
									{
										from.SendMessage("You darken the mix with black pearl...");
										double dCalc = sdtub.Uses;
										dCalc /= 5;
										iConsume = ((int)dCalc) + 1;
									}
									else //pla: This will never happen now
										from.SendMessage("You attempt to darken the mix, but it will go no darker.");

								}
								else
								{
									if (sdtub.LightenMix())
									{
										from.SendMessage("You lighten the mix with sulfurous ash...");
										double dCalc = sdtub.Uses;
										dCalc /= 5;
										iConsume = ((int)dCalc) + 1;
									}
									else //pla: This will never happen now
										from.SendMessage("You attempt to lighten the mix, but it will go no lighter.");
								}

								for (int i = 0; i < iConsume; i++)
									ConsumeRes(from, typeRes, craftSystem, ref resHue, ref maxAmount, ConsumeType.All, ref message);

								from.PlaySound(0x242);
							}
						}
						else
						{
							// Make sure they've got a regular dye tub / a special one of the same color

							Item[] dtub = ((Container)from.Backpack).FindItemsByType(typeof(DyeTub), true);
							DyeTub dt = null;

							int iFound = 0;

							if (dtub.Length > 0)
							{
								for (int i = 0; i < dtub.Length; i++)
								{
									if (dtub[i] is SpecialDyeTub)
									{
										// Is the same color?
										if (((SpecialDyeTub)dtub[i]).StoredColorName == m_NameString && ((SpecialDyeTub)dtub[i]).Uses < 100 && !((SpecialDyeTub)dtub[i]).Prepped)
										{
											dt = (DyeTub)dtub[i];
											iFound++;
										}

										continue;
									}
									else
									{
										dt = (DyeTub)dtub[i];
										iFound++;
									}
								}
							}

							sdtub = (SpecialDyeTub)item;

							if (dt == null)
							{
								from.SendMessage("You need a fresh dye tub or one that is not yet full and of the same color as the dye you are preparing.");
								sdtub.Delete();
							}
							else
							{
								if (iFound > 1)
								{
									// Pla, 04/01/07
									// This code will never be called now but left it in for sanity
									// -----------------------------------------------------------------
									// Let the target take over from here
									//from.Target = new SpecialDyeTubTarget( this, typeRes, craftSystem, ref resHue, ref maxAmount, ref message, ref item, m_NameString, 0 );
									//from.SendMessage("Select the dye tub you wish to use for the process.");
								}
								else
								{

									if (dt is SpecialDyeTub)
									{
										sdtub.Delete();
										((SpecialDyeTub)dt).Uses++;
										from.SendMessage("You mix the dye and add it to an existing batch.");
									}
									else
									{
										sdtub.StoreColor(m_NameString);
										dt.Delete();
										from.SendMessage("You successfully mix the dye.");
										from.AddToBackpack(item);
									}
									ConsumeRes(from, typeRes, craftSystem, ref resHue, ref maxAmount, ConsumeType.All, ref message);
								}
							}
						}
					}

					if (craftSystem is DefTinkering &&
						item is BaseTinkerTrap)
					{
						//Need to send target cursor to target
						//the trappable container
						bTinkerTrap = true;

						int power = (int)from.Skills[SkillName.Tinkering].Value + Utility.Random(0, 15);
						if (power <= 10) power = 10;
						((BaseTinkerTrap)item).Power = power;
						from.SendMessage("Target the container you wish to trap.");
						from.Target = new TrappableContainerTarget(this, item, craftSystem, toolBroken, tool);
					}

					if (!bTinkerTrap && (!(item is SpecialDyeTub || item is SpecialDye)))
					{
						from.AddToBackpack(item);
					}

					//from.PlaySound( 0x57 );
				}

				if (!bTinkerTrap)
				{
					int num = craftSystem.PlayEndingEffect(from, false, true, toolBroken, endquality, makersMark, this);

					if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
						from.SendGump(new CraftGump(from, craftSystem, tool, num));
					else if (num > 0)
						from.SendLocalizedMessage(num);
				}
			}
			else if (!allRequiredSkills)
			{
				if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
					from.SendGump(new CraftGump(from, craftSystem, tool, 1044153));
				else
					from.SendLocalizedMessage(1044153); // You don't have the required skills to attempt this item.
			}
			else
			{

				ConsumeType consumeType = (UseAllRes ? ConsumeType.Fail : ConsumeType.Half);
				int resHue = 0;
				int maxAmount = 0;

				object message = null;

				// Not enough resource to craft it
				if (!ConsumeRes(from, typeRes, craftSystem, ref resHue, ref maxAmount, consumeType, ref message))
				{
					if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
						from.SendGump(new CraftGump(from, craftSystem, tool, message));
					else if (message is int && (int)message > 0)
						from.SendLocalizedMessage((int)message);
					else if (message is string)
						from.SendMessage((string)message);

					return;
				}

				tool.UsesRemaining--;

				if (tool.UsesRemaining < 1)
					toolBroken = true;

				if (toolBroken)
					tool.Delete();

				// SkillCheck failed.
				int num = craftSystem.PlayEndingEffect(from, true, true, toolBroken, endquality, false, this);

				if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
					from.SendGump(new CraftGump(from, craftSystem, tool, num));
				else if (num > 0)
					from.SendLocalizedMessage(num);
			}
		}
Exemple #43
0
        public static EnhanceResult Invoke(Mobile from, CraftSystem craftSystem, ITool tool, Item item, CraftResource resource, Type resType, ref object resMessage)
        {
            if (item == null)
            {
                return(EnhanceResult.BadItem);
            }

            if (item is GargishNecklace || item is GargishEarrings)
            {
                return(EnhanceResult.BadItem);
            }

            if (!item.IsChildOf(from.Backpack))
            {
                return(EnhanceResult.NotInBackpack);
            }

            IResource ires = item as IResource;

            if (!CanEnhance(item) || ires == null)
            {
                return(EnhanceResult.BadItem);
            }

            if (item is IArcaneEquip)
            {
                IArcaneEquip eq = (IArcaneEquip)item;
                if (eq.IsArcane)
                {
                    return(EnhanceResult.BadItem);
                }
            }

            if (item is BaseWeapon && Spells.Mysticism.EnchantSpell.IsUnderSpellEffects(from, (BaseWeapon)item))
            {
                return(EnhanceResult.Enchanted);
            }

            if (CraftResources.IsStandard(resource))
            {
                return(EnhanceResult.BadResource);
            }

            int num = craftSystem.CanCraft(from, tool, item.GetType());

            if (num > 0)
            {
                resMessage = num;
                return(EnhanceResult.None);
            }

            CraftItem craftItem = craftSystem.CraftItems.SearchFor(item.GetType());

            if (IsSpecial(item, craftSystem))
            {
                craftItem = craftSystem.CraftItems.SearchForSubclass(item.GetType());
            }

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

            #region Mondain's Legacy
            if (craftItem.ForceNonExceptional)
            {
                return(EnhanceResult.BadItem);
            }
            #endregion

            bool allRequiredSkills = false;
            if (craftItem.GetSuccessChance(from, resType, craftSystem, false, ref allRequiredSkills) <= 0.0)
            {
                return(EnhanceResult.NoSkill);
            }

            CraftResourceInfo info = CraftResources.GetInfo(resource);

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

            CraftAttributeInfo attributes = info.AttributeInfo;

            if (attributes == null)
            {
                return(EnhanceResult.BadResource);
            }

            int resHue = 0, maxAmount = 0;

            if (!craftItem.ConsumeRes(from, resType, craftSystem, ref resHue, ref maxAmount, ConsumeType.None, ref resMessage))
            {
                return(EnhanceResult.NoResources);
            }

            if (!CraftResources.IsStandard(ires.Resource))
            {
                return(EnhanceResult.AlreadyEnhanced);
            }

            if (craftSystem is DefBlacksmithy)
            {
                AncientSmithyHammer hammer = from.FindItemOnLayer(Layer.OneHanded) as AncientSmithyHammer;
                if (hammer != null)
                {
                    hammer.UsesRemaining--;
                    if (hammer.UsesRemaining < 1)
                    {
                        hammer.Delete();
                    }
                }
            }

            int phys = 0, fire = 0, cold = 0, pois = 0, nrgy = 0;
            int dura = 0, luck = 0, lreq = 0, dinc = 0;
            int baseChance = 0;

            bool physBonus = false;
            bool fireBonus = false;
            bool coldBonus = false;
            bool nrgyBonus = false;
            bool poisBonus = false;
            bool duraBonus = false;
            bool luckBonus = false;
            bool lreqBonus = false;
            bool dincBonus = false;

            if (item is BaseWeapon)
            {
                BaseWeapon weapon = (BaseWeapon)item;

                if (weapon.ExtendedWeaponAttributes.AssassinHoned > 0)
                {
                    return(EnhanceResult.BadItem);
                }

                baseChance = 20;

                dura = weapon.MaxHitPoints;
                luck = weapon.Attributes.Luck;
                lreq = weapon.WeaponAttributes.LowerStatReq;
                dinc = weapon.Attributes.WeaponDamage;

                fireBonus = (attributes.WeaponFireDamage > 0);
                coldBonus = (attributes.WeaponColdDamage > 0);
                nrgyBonus = (attributes.WeaponEnergyDamage > 0);
                poisBonus = (attributes.WeaponPoisonDamage > 0);

                duraBonus = (attributes.WeaponDurability > 0);
                luckBonus = (attributes.WeaponLuck > 0);
                lreqBonus = (attributes.WeaponLowerRequirements > 0);
                dincBonus = (dinc > 0);
            }
            else if (item is BaseArmor)
            {
                BaseArmor armor = (BaseArmor)item;

                baseChance = 20;

                phys = armor.PhysicalResistance;
                fire = armor.FireResistance;
                cold = armor.ColdResistance;
                pois = armor.PoisonResistance;
                nrgy = armor.EnergyResistance;

                dura = armor.MaxHitPoints;
                luck = armor.Attributes.Luck;
                lreq = armor.ArmorAttributes.LowerStatReq;

                physBonus = (attributes.ArmorPhysicalResist > 0);
                fireBonus = (attributes.ArmorFireResist > 0);
                coldBonus = (attributes.ArmorColdResist > 0);
                nrgyBonus = (attributes.ArmorEnergyResist > 0);
                poisBonus = (attributes.ArmorPoisonResist > 0);

                duraBonus = (attributes.ArmorDurability > 0);
                luckBonus = (attributes.ArmorLuck > 0);
                lreqBonus = (attributes.ArmorLowerRequirements > 0);
                dincBonus = false;
            }
            else if (item is FishingPole)
            {
                FishingPole pole = (FishingPole)item;

                baseChance = 20;

                luck = pole.Attributes.Luck;

                luckBonus = (attributes.ArmorLuck > 0);
                lreqBonus = (attributes.ArmorLowerRequirements > 0);
                dincBonus = false;
            }

            int skill = from.Skills[craftSystem.MainSkill].Fixed / 10;

            if (skill >= 100)
            {
                baseChance -= (skill - 90) / 10;
            }

            EnhanceResult res = EnhanceResult.Success;

            PlayerMobile user = from as PlayerMobile;

            if (physBonus)
            {
                CheckResult(ref res, baseChance + phys);
            }

            if (fireBonus)
            {
                CheckResult(ref res, baseChance + fire);
            }

            if (coldBonus)
            {
                CheckResult(ref res, baseChance + cold);
            }

            if (nrgyBonus)
            {
                CheckResult(ref res, baseChance + nrgy);
            }

            if (poisBonus)
            {
                CheckResult(ref res, baseChance + pois);
            }

            if (duraBonus)
            {
                CheckResult(ref res, baseChance + (dura / 40));
            }

            if (luckBonus)
            {
                CheckResult(ref res, baseChance + 10 + (luck / 2));
            }

            if (lreqBonus)
            {
                CheckResult(ref res, baseChance + (lreq / 4));
            }

            if (dincBonus)
            {
                CheckResult(ref res, baseChance + (dinc / 4));
            }

            if (user.NextEnhanceSuccess)
            {
                user.NextEnhanceSuccess = false;
                user.SendLocalizedMessage(1149969); // The magical aura that surrounded you disipates and you feel that your item enhancement chances have returned to normal.
                res = EnhanceResult.Success;
            }

            switch (res)
            {
            case EnhanceResult.Broken:
            {
                if (!craftItem.ConsumeRes(from, resType, craftSystem, ref resHue, ref maxAmount, ConsumeType.Half, ref resMessage))
                {
                    return(EnhanceResult.NoResources);
                }

                item.Delete();
                break;
            }

            case EnhanceResult.Success:
            {
                if (!craftItem.ConsumeRes(from, resType, craftSystem, ref resHue, ref maxAmount, ConsumeType.All, ref resMessage))
                {
                    return(EnhanceResult.NoResources);
                }

                if (craftItem.CaddelliteCraft)
                {
                    Caddellite.TryInfuse(from, item, craftSystem);
                }

                if (item is IResource)
                {
                    ((IResource)item).Resource = resource;
                }

                if (item is BaseWeapon)
                {
                    BaseWeapon w = (BaseWeapon)item;
                    w.DistributeMaterialBonus(attributes);

                    int hue = w.GetElementalDamageHue();

                    if (hue > 0)
                    {
                        w.Hue = hue;
                    }
                }
                else if (item is BaseArmor)
                {
                    ((BaseArmor)item).DistributeMaterialBonus(attributes);
                }
                else if (item is FishingPole)
                {
                    ((FishingPole)item).DistributeMaterialBonus(attributes);
                }
                break;
            }

            case EnhanceResult.Failure:
            {
                if (!craftItem.ConsumeRes(from, resType, craftSystem, ref resHue, ref maxAmount, ConsumeType.Half, ref resMessage))
                {
                    return(EnhanceResult.NoResources);
                }

                break;
            }
            }

            return(res);
        }
Exemple #44
0
		public void Craft( Mobile from, CraftSystem craftSystem, Type typeRes, BaseTool tool )
		{
			if ( from.BeginAction( typeof( CraftSystem ) ) )
			{
				if( RequiredExpansion == Expansion.None || ( from.NetState != null && from.NetState.SupportsExpansion( RequiredExpansion ) ) )
				{
					bool allRequiredSkills = true;
					double chance = GetSuccessChance( from, typeRes, craftSystem, false, ref allRequiredSkills );

					if ( allRequiredSkills && chance >= 0.0 )
					{
						if( this.Recipe == null || !(from is PlayerMobile) || ((PlayerMobile)from).HasRecipe( this.Recipe ) )
						{
							int badCraft = craftSystem.CanCraft( from, tool, m_Type );

							if( badCraft <= 0 )
							{
								int resHue = 0;
								int maxAmount = 0;
								object message = null;

								if( ConsumeRes( from, typeRes, craftSystem, ref resHue, ref maxAmount, ConsumeType.None, ref message ) )
								{
									message = null;

									if( ConsumeAttributes( from, ref message, false ) )
									{
										CraftContext context = craftSystem.GetContext( from );

										if( context != null )
											context.OnMade( this );

										int iMin = craftSystem.MinCraftEffect;
										int iMax = (craftSystem.MaxCraftEffect - iMin) + 1;
										int iRandom = Utility.Random( iMax );
										iRandom += iMin + 1;
										new InternalTimer( from, craftSystem, this, typeRes, tool, iRandom ).Start();
									}
									else
									{
										from.EndAction( typeof( CraftSystem ) );
										from.SendGump( new CraftGump( from, craftSystem, tool, message ) );
									}
								}
								else
								{
									from.EndAction( typeof( CraftSystem ) );
									from.SendGump( new CraftGump( from, craftSystem, tool, message ) );
								}
							}
							else
							{
								from.EndAction( typeof( CraftSystem ) );
								from.SendGump( new CraftGump( from, craftSystem, tool, badCraft ) );
							}
						}
						else
						{
							from.EndAction( typeof( CraftSystem ) );
							from.SendGump( new CraftGump( from, craftSystem, tool, 1072847 ) ); // You must learn that recipe from a scroll.
						}
					}
					else
					{
						from.EndAction( typeof( CraftSystem ) );
						from.SendGump( new CraftGump( from, craftSystem, tool, 1044153 ) ); // You don't have the required skills to attempt this item.
					}
				}
				else
				{
					from.EndAction( typeof( CraftSystem ) );
					from.SendGump( new CraftGump( from, craftSystem, tool, RequiredExpansionMessage( RequiredExpansion ) ) ); //The {0} expansion is required to attempt this item.
				}
			}
			else
			{
				from.SendLocalizedMessage( 500119 ); // You must wait to perform another action
			}
		}
		public void CompleteCraft(int quality, bool makersMark, Mobile from, CraftSystem craftSystem, Type typeRes, BaseTool tool, CustomCraft customCraft)
		{
			int badCraft = craftSystem.CanCraft(from, tool, m_Type);

			if (badCraft > 0)
			{
				if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
					from.SendGump(new CraftGump(from, craftSystem, tool, badCraft));
				else
					from.SendLocalizedMessage(badCraft);

				return;
			}

			int checkResHue = 0, checkMaxAmount = 0;
			object checkMessage = null;

			// Not enough resource to craft it
			if (!ConsumeRes(from, typeRes, craftSystem, ref checkResHue, ref checkMaxAmount, ConsumeType.None, ref checkMessage))
			{
				if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
					from.SendGump(new CraftGump(from, craftSystem, tool, checkMessage));
				else if (checkMessage is int && (int)checkMessage > 0)
					from.SendLocalizedMessage((int)checkMessage);
				else if (checkMessage is string)
					from.SendMessage((string)checkMessage);

				return;
			}
			else if (!ConsumeAttributes(from, ref checkMessage, false))
			{
				if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
					from.SendGump(new CraftGump(from, craftSystem, tool, checkMessage));
				else if (checkMessage is int && (int)checkMessage > 0)
					from.SendLocalizedMessage((int)checkMessage);
				else if (checkMessage is string)
					from.SendMessage((string)checkMessage);

				return;
			}

			bool toolBroken = false;

			int ignored = 1;
			int endquality = 1;

			bool allRequiredSkills = true;

			if (CheckSkills(from, typeRes, craftSystem, ref ignored, ref allRequiredSkills))
			{
				// Resource
				int resHue = 0;
				int maxAmount = 0;

				object message = null;

				// Not enough resource to craft it
				if (!ConsumeRes(from, typeRes, craftSystem, ref resHue, ref maxAmount, ConsumeType.All, ref message))
				{
					if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
						from.SendGump(new CraftGump(from, craftSystem, tool, message));
					else if (message is int && (int)message > 0)
						from.SendLocalizedMessage((int)message);
					else if (message is string)
						from.SendMessage((string)message);

					return;
				}
				else if (!ConsumeAttributes(from, ref message, true))
				{
					if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
						from.SendGump(new CraftGump(from, craftSystem, tool, message));
					else if (message is int && (int)message > 0)
						from.SendLocalizedMessage((int)message);
					else if (message is string)
						from.SendMessage((string)message);

					return;
				}

				tool.UsesRemaining--;

				if (craftSystem is DefBlacksmithy)
				{
					AncientSmithyHammer hammer = from.FindItemOnLayer(Layer.OneHanded) as AncientSmithyHammer;

					if (hammer != null && hammer != tool)
					{
						#region Mondain's Legacy
						if (hammer is HammerOfHephaestus)
						{
							if (hammer.UsesRemaining > 0)
								hammer.UsesRemaining--;

							if (hammer.UsesRemaining < 1)
								from.PlaceInBackpack(hammer);
						}
						else
						{
							hammer.UsesRemaining--;

							if (hammer.UsesRemaining < 1)
								hammer.Delete();
						}
						#endregion
					}
				}

				#region Mondain's Legacy
				if (tool is HammerOfHephaestus)
				{
					if (tool.UsesRemaining < 1)
						tool.UsesRemaining = 0;
				}
				else
				{
					if (tool.UsesRemaining < 1)
						toolBroken = true;

					if (toolBroken)
						tool.Delete();
				}
				#endregion

				int num = 0;

				Item item;
				if (customCraft != null)
				{
					item = customCraft.CompleteCraft(out num);
				}
				else if (typeof(MapItem).IsAssignableFrom(ItemType) && from.Map != Map.Trammel && from.Map != Map.Felucca)
				{
					item = new IndecipherableMap();
					from.SendLocalizedMessage(1070800); // The map you create becomes mysteriously indecipherable.
				}
				else
				{
					item = Activator.CreateInstance(ItemType) as Item;
				}

				if (item != null)
				{
					#region Mondain's Legacy
					if (item is Board)
					{
						Type resourceType = typeRes;

						if (resourceType == null)
							resourceType = Resources.GetAt(0).ItemType;

						CraftResource thisResource = CraftResources.GetFromType(resourceType);

						switch (thisResource)
						{
							case CraftResource.OakWood: item = new OakBoard(); break;
							case CraftResource.AshWood: item = new AshBoard(); break;
							case CraftResource.YewWood: item = new YewBoard(); break;
							case CraftResource.Heartwood: item = new HeartwoodBoard(); break;
							case CraftResource.Bloodwood: item = new BloodwoodBoard(); break;
							case CraftResource.Frostwood: item = new FrostwoodBoard(); break;
							default: item = new Board(); break;
						}
					}
					#endregion

					if (item is ICraftable)
						endquality = ((ICraftable)item).OnCraft(quality, makersMark, from, craftSystem, typeRes, tool, this, resHue);
					else if (item.Hue == 0)
						item.Hue = resHue;

					if (maxAmount > 0)
					{
						if (!item.Stackable && item is IUsesRemaining)
							((IUsesRemaining)item).UsesRemaining *= maxAmount;
						else
							item.Amount = maxAmount;
					}

					from.AddToBackpack(item);

//I Added FOR CRAFTBAG                    
                    Container craftbag = GetCraftBag(from);
                    if (!craftbag.TryDropItem(from, item, false))
                    {
                        from.AddToBackpack(item);
                    }
//I Added For craftbacg above. The original below
//originaly was there above                    from.AddToBackpack(item);
					if (from.AccessLevel > AccessLevel.Player)
						CommandLogging.WriteLine(from, "Crafting {0} with craft system {1}", CommandLogging.Format(item), craftSystem.GetType().Name);

					//from.PlaySound( 0x57 );
				}

				if (num == 0)
					num = craftSystem.PlayEndingEffect(from, false, true, toolBroken, endquality, makersMark, this);

				bool queryFactionImbue = false;
				int availableSilver = 0;
				FactionItemDefinition def = null;
				Faction faction = null;

				if (item is IFactionItem)
				{
					def = FactionItemDefinition.Identify(item);

					if (def != null)
					{
						faction = Faction.Find(from);

						if (faction != null)
						{
							Town town = Town.FromRegion(from.Region);

							if (town != null && town.Owner == faction)
							{
								Container pack = from.Backpack;

								if (pack != null)
								{
									availableSilver = pack.GetAmount(typeof(Silver));

									if (availableSilver >= def.SilverCost)
										queryFactionImbue = Faction.IsNearType(from, def.VendorType, 12);
								}
							}
						}
					}
				}

                // TODO: Scroll imbuing

                if (queryFactionImbue)
                    from.SendGump(new FactionImbueGump(quality, item, from, craftSystem, tool, num, availableSilver, faction, def));
                else if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
//I added for autoloop                	
                {
                    CraftContext context = craftSystem.GetContext(from);
                    if (context != null && context.AutoLoop)
                    {
                        context.Count++;
                        if (context.TotalCount == 0 || context.Count < context.TotalCount)
                        {
                            this.Craft(from, craftSystem, typeRes, tool);
                        }
                        else
                            from.SendGump(new CraftGump(from, craftSystem, tool, num));
                    }
                    else
                        from.SendGump(new CraftGump(from, craftSystem, tool, num));
                }
                	
//I ADDED autoloop this originaly there                   from.SendGump(new CraftGump(from, craftSystem, tool, num));
                else if (num > 0)
                    from.SendLocalizedMessage(num);
            }
            else if (!allRequiredSkills)
            {
                if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
                    from.SendGump(new CraftGump(from, craftSystem, tool, 1044153));
                else
                    from.SendLocalizedMessage(1044153); // You don't have the required skills to attempt this item.
            }
            else
            {
                ConsumeType consumeType = (UseAllRes ? ConsumeType.Half : ConsumeType.All);
                int resHue = 0;
                int maxAmount = 0;

				object message = null;

				// Not enough resource to craft it
				if (!ConsumeRes(from, typeRes, craftSystem, ref resHue, ref maxAmount, consumeType, ref message, true))
				{
					if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
						from.SendGump(new CraftGump(from, craftSystem, tool, message));
					else if (message is int && (int)message > 0)
						from.SendLocalizedMessage((int)message);
					else if (message is string)
						from.SendMessage((string)message);

					return;
				}

				tool.UsesRemaining--;

				if (tool.UsesRemaining < 1)
					toolBroken = true;

				if (toolBroken)
					tool.Delete();

				// SkillCheck failed.
				int num = craftSystem.PlayEndingEffect(from, true, true, toolBroken, endquality, false, this);

				if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
//I added auto loop
                 {
                    CraftContext context = craftSystem.GetContext(from);
                    if (context != null && context.AutoLoop)
                    {
                        context.Count++;
                        if (context.TotalCount == 0 || context.Count < context.TotalCount)
                        {
                            this.Craft(from, craftSystem, typeRes, tool);
                        }
                        else
                            from.SendGump(new CraftGump(from, craftSystem, tool, num));
                    }
                    else
                        from.SendGump(new CraftGump(from, craftSystem, tool, num));
                }
//I added autoloop this originaly there                    from.SendGump(new CraftGump(from, craftSystem, tool, num));
                else if (num > 0)
                    from.SendLocalizedMessage(num);
            }
        }
Exemple #46
0
            protected override void OnTarget(Mobile from, object targeted)
            {
                int number;

                if (m_CraftSystem.CanCraft(from, m_Tool, targeted.GetType()) == 1044267)
                {
                    number = 1044282;                     // You must be near a forge and and anvil to repair items. * Yes, there are two and's *
                }
                else if (targeted is BaseWeapon)
                {
                    BaseWeapon weapon   = (BaseWeapon)targeted;
                    SkillName  skill    = m_CraftSystem.MainSkill;
                    int        toWeaken = 0;

                    if (skill != SkillName.Tailoring)
                    {
                        double skillLevel = from.Skills[skill].Base;

                        if (skillLevel >= 90.0)
                        {
                            toWeaken = 1;
                        }
                        else if (skillLevel >= 70.0)
                        {
                            toWeaken = 2;
                        }
                        else
                        {
                            toWeaken = 3;
                        }
                    }

                    if (m_CraftSystem.CraftItems.SearchForSubclass(weapon.GetType()) == null && !IsSpecialWeapon(weapon))
                    {
                        number = 1061136;                     // That item cannot be repaired.
                    }
                    else if (!weapon.IsChildOf(from.Backpack))
                    {
                        number = 1044275;                         // The item must be in your backpack to repair it.
                    }
                    else if (weapon.PoisonCharges != 0)
                    {
                        number = 1005012;                         // You cannot repair an item while a caustic substance is on it.
                    }
                    else if (weapon.MaxHitPoints <= 0 || weapon.HitPoints == weapon.MaxHitPoints)
                    {
                        number = 1044281;                         // That item is in full repair
                    }
                    else if (weapon.MaxHitPoints <= toWeaken)
                    {
                        number = 1044278;                         // That item has been repaired many times, and will break if repairs are attempted again.
                    }
                    else
                    {
                        if (CheckWeaken(from, skill, weapon.HitPoints, weapon.MaxHitPoints))
                        {
                            weapon.MaxHitPoints -= toWeaken;
                            weapon.HitPoints     = Math.Max(0, weapon.HitPoints - toWeaken);
                        }

                        if (CheckRepairDifficulty(from, skill, weapon.HitPoints, weapon.MaxHitPoints))
                        {
                            number = 1044279;                             // You repair the item.
                            m_CraftSystem.PlayCraftEffect(from);
                            weapon.HitPoints = weapon.MaxHitPoints;
                        }
                        else
                        {
                            number = 1061137;                         // You fail to repair the item.
                            m_CraftSystem.PlayCraftEffect(from);
                        }
                    }
                }
                else if (targeted is BaseArmor)
                {
                    BaseArmor armor    = (BaseArmor)targeted;
                    SkillName skill    = m_CraftSystem.MainSkill;
                    int       toWeaken = 0;

                    if (skill != SkillName.Tailoring)
                    {
                        double skillLevel = from.Skills[skill].Base;

                        if (skillLevel >= 90.0)
                        {
                            toWeaken = 1;
                        }
                        else if (skillLevel >= 70.0)
                        {
                            toWeaken = 2;
                        }
                        else
                        {
                            toWeaken = 3;
                        }
                    }

                    if (m_CraftSystem.CraftItems.SearchForSubclass(armor.GetType()) == null)
                    {
                        number = 1061136;                     // That item cannot be repaired.
                    }
                    else if (!armor.IsChildOf(from.Backpack))
                    {
                        number = 1044275;                         // The item must be in your backpack to repair it.
                    }
                    else if (armor.MaxHitPoints <= 0 || armor.HitPoints == armor.MaxHitPoints)
                    {
                        number = 1044281;                         // That item is in full repair
                    }
                    else if (armor.MaxHitPoints <= toWeaken)
                    {
                        number = 1044278;                         // That item has been repaired many times, and will break if repairs are attempted again.
                    }
                    else
                    {
                        if (CheckWeaken(from, skill, armor.HitPoints, armor.MaxHitPoints))
                        {
                            armor.MaxHitPoints -= toWeaken;
                            armor.HitPoints     = Math.Max(0, armor.HitPoints - toWeaken);
                        }

                        if (CheckRepairDifficulty(from, skill, armor.HitPoints, armor.MaxHitPoints))
                        {
                            number = 1044279;                             // You repair the item.
                            m_CraftSystem.PlayCraftEffect(from);
                            armor.HitPoints = armor.MaxHitPoints;
                        }
                        else
                        {
                            number = 1061137;                             // You fail to repair the item.
                            m_CraftSystem.PlayCraftEffect(from);
                        }
                    }
                }
                else if (targeted is BaseClothing)
                {
                    BaseClothing clothing = (BaseClothing)targeted;
                    SkillName    skill    = m_CraftSystem.MainSkill;
                    int          toWeaken = 0;

                    if (skill != SkillName.Tailoring)
                    {
                        double skillLevel = from.Skills[skill].Base;

                        if (skillLevel >= 90.0)
                        {
                            toWeaken = 1;
                        }
                        else if (skillLevel >= 70.0)
                        {
                            toWeaken = 2;
                        }
                        else
                        {
                            toWeaken = 3;
                        }
                    }

                    if (m_CraftSystem.CraftItems.SearchForSubclass(clothing.GetType()) == null && !IsSpecialClothing(clothing) && !((targeted is TribalMask) || (targeted is HornedTribalMask)))
                    {
                        number = 1061136;                         // That item cannot be repaired.
                    }
                    else if (!clothing.IsChildOf(from.Backpack))
                    {
                        number = 1044275;                         // The item must be in your backpack to repair it.
                    }
                    else if (clothing.MaxHitPoints <= 0 || clothing.HitPoints == clothing.MaxHitPoints)
                    {
                        number = 1044281;                         // That item is in full repair
                    }
                    else if (clothing.MaxHitPoints <= toWeaken)
                    {
                        number = 1044278;                         // That item has been repaired many times, and will break if repairs are attempted again.
                    }
                    else
                    {
                        if (CheckWeaken(from, skill, clothing.HitPoints, clothing.MaxHitPoints))
                        {
                            clothing.MaxHitPoints -= toWeaken;
                            clothing.HitPoints     = Math.Max(0, clothing.HitPoints - toWeaken);
                        }

                        if (CheckRepairDifficulty(from, skill, clothing.HitPoints, clothing.MaxHitPoints))
                        {
                            number = 1044279;                             // You repair the item.
                            m_CraftSystem.PlayCraftEffect(from);
                            clothing.HitPoints = clothing.MaxHitPoints;
                        }
                        else
                        {
                            number = 1061137;                             // You fail to repair the item.
                            m_CraftSystem.PlayCraftEffect(from);
                        }
                    }
                }
                else if (targeted is Item)
                {
                    number = 1061136;                     // That item cannot be repaired.
                }
                else
                {
                    number = 500426;                     // You can't repair that.
                }

                from.SendGump(new CraftGump(from, m_CraftSystem, m_Tool, number));
            }
Exemple #47
0
		public void CompleteCraft(
			int quality,
			bool makersMark,
			Mobile from,
			CraftSystem craftSystem,
			Type typeRes,
			BaseTool tool,
			CustomCraft customCraft)
		{
			int badCraft = craftSystem.CanCraft(from, tool, m_Type);

			if (badCraft > 0)
			{
				if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
				{
					from.SendGump(new CraftGump(from, craftSystem, tool, badCraft));
				}
				else
				{
					from.SendLocalizedMessage(badCraft);
				}

                AutoCraftTimer.EndTimer(from);

				return;
			}

			int checkResHue = 0, checkMaxAmount = 0;
			object checkMessage = null;

			// Not enough resource to craft it
			if (!ConsumeRes(from, typeRes, craftSystem, ref checkResHue, ref checkMaxAmount, ConsumeType.None, ref checkMessage))
			{
				if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
				{
					from.SendGump(new CraftGump(from, craftSystem, tool, checkMessage));
				}
				else if (checkMessage is int && (int)checkMessage > 0)
				{
					from.SendLocalizedMessage((int)checkMessage);
				}
				else if (checkMessage is string)
				{
					from.SendMessage((string)checkMessage);
				}

                AutoCraftTimer.EndTimer(from);

				return;
			}
			else if (!ConsumeAttributes(from, ref checkMessage, false))
			{
				if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
				{
					from.SendGump(new CraftGump(from, craftSystem, tool, checkMessage));
				}
				else if (checkMessage is int && (int)checkMessage > 0)
				{
					from.SendLocalizedMessage((int)checkMessage);
				}
				else if (checkMessage is string)
				{
					from.SendMessage((string)checkMessage);
				}

                AutoCraftTimer.EndTimer(from);

				return;
			}

			bool toolBroken = false;

			int ignored = 1;
			int endquality = 1;

			bool allRequiredSkills = true;

			if (CheckSkills(from, typeRes, craftSystem, ref ignored, ref allRequiredSkills))
			{
				// Resource
				int resHue = 0;
				int maxAmount = 0;

				object message = null;

				// Not enough resource to craft it
				if (!ConsumeRes(from, typeRes, craftSystem, ref resHue, ref maxAmount, ConsumeType.All, ref message))
				{
					if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
					{
						from.SendGump(new CraftGump(from, craftSystem, tool, message));
					}
					else if (message is int && (int)message > 0)
					{
						from.SendLocalizedMessage((int)message);
					}
					else if (message is string)
					{
						from.SendMessage((string)message);
					}

                    AutoCraftTimer.EndTimer(from);

					return;
				}
				else if (!ConsumeAttributes(from, ref message, true))
				{
					if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
					{
						from.SendGump(new CraftGump(from, craftSystem, tool, message));
					}
					else if (message is int && (int)message > 0)
					{
						from.SendLocalizedMessage((int)message);
					}
					else if (message is string)
					{
						from.SendMessage((string)message);
					}

                    AutoCraftTimer.EndTimer(from);

					return;
				}

				tool.UsesRemaining--;

				if (craftSystem is DefBlacksmithy)
				{
					AncientSmithyHammer hammer = from.FindItemOnLayer(Layer.OneHanded) as AncientSmithyHammer;
					if (hammer != null && hammer != tool)
					{
						#region Mondain's Legacy
						if (hammer is HammerOfHephaestus)
						{
							if (hammer.UsesRemaining > 0)
							{
								hammer.UsesRemaining--;
							}

							if (hammer.UsesRemaining < 1)
							{
								from.PlaceInBackpack(hammer);
							}
						}
						else
						{
							hammer.UsesRemaining--;

							if (hammer.UsesRemaining < 1)
							{
								hammer.Delete();
							}
						}
						#endregion
					}
				}

				#region Mondain's Legacy
				if (tool is HammerOfHephaestus)
				{
					if (tool.UsesRemaining < 1)
					{
						tool.UsesRemaining = 0;
					}
				}
				else
				{
					if (tool.UsesRemaining < 1)
					{
						toolBroken = true;
					}

					if (toolBroken)
					{
						tool.Delete();
					}
				}
				#endregion

				int num = 0;

				Item item;
				if (customCraft != null)
				{
					item = customCraft.CompleteCraft(out num);
				}
				else if (typeof(MapItem).IsAssignableFrom(ItemType) && from.Map != Map.Trammel && from.Map != Map.Felucca)
				{
					item = new IndecipherableMap();
					from.SendLocalizedMessage(1070800); // The map you create becomes mysteriously indecipherable.
				}
				else
				{
					item = Activator.CreateInstance(ItemType) as Item;
				}

				if (item != null)
				{
					#region Mondain's Legacy
					if (item is Board)
					{
						Type resourceType = typeRes;

						if (resourceType == null)
						{
							resourceType = Resources.GetAt(0).ItemType;
						}

						CraftResource thisResource = CraftResources.GetFromType(resourceType);

						switch (thisResource)
						{
							case CraftResource.OakWood:
								item = new OakBoard();
								break;
							case CraftResource.AshWood:
								item = new AshBoard();
								break;
							case CraftResource.YewWood:
								item = new YewBoard();
								break;
							case CraftResource.Heartwood:
								item = new HeartwoodBoard();
								break;
							case CraftResource.Bloodwood:
								item = new BloodwoodBoard();
								break;
							case CraftResource.Frostwood:
								item = new FrostwoodBoard();
								break;
							default:
								item = new Board();
								break;
						}
					}
					#endregion

					if (item is ICraftable)
					{
						endquality = ((ICraftable)item).OnCraft(quality, makersMark, from, craftSystem, typeRes, tool, this, resHue);
					}
					else if (item is Food)
					{
						((Food)item).PlayerConstructed = true;
					}
					else if (item.Hue == 0)
					{
						item.Hue = resHue;
					}

					if (maxAmount > 0)
					{
						if (!item.Stackable && item is IUsesRemaining)
						{
							((IUsesRemaining)item).UsesRemaining *= maxAmount;
						}
						else
						{
							item.Amount = maxAmount;
						}
					}

					#region Plant Pigments
					if (item is PlantPigment && (craftSystem is DefAlchemy || craftSystem is DefCooking))
					{
						((PlantPigment)item).PigmentHue = PlantPigmentHueInfo.HueFromPlantHue(m_PlantHue);
					}

					if (item is NaturalDye && (craftSystem is DefAlchemy || craftSystem is DefCooking))
					{
						((NaturalDye)item).PigmentHue = PlantPigmentHueInfo.GetInfo(m_PlantPigmentHue).PlantPigmentHue;
					}

					if (item is SoftenedReeds && (craftSystem is DefAlchemy || craftSystem is DefCooking))
					{
						((SoftenedReeds)item).PlantHue = PlantHueInfo.GetInfo(m_PlantHue).PlantHue;
					}

					if (item is BaseContainer && (craftSystem is DefBasketweaving))
					{
						(item).Hue = PlantHueInfo.GetInfo(m_PlantHue).Hue;
					}

                    CraftContext context = craftSystem.GetContext(from);

                    if (context.QuestOption == CraftQuestOption.QuestItem)
                    {
                        PlayerMobile px = from as PlayerMobile;

                        if (!QuestHelper.CheckItem(px, item))
                            from.SendLocalizedMessage(1072355, null, 0x23); // That item does not match any of your quest criteria	
                    }
					#endregion

					from.AddToBackpack(item);

					if (from.IsStaff())
					{
						CommandLogging.WriteLine(
							from, "Crafting {0} with craft system {1}", CommandLogging.Format(item), craftSystem.GetType().Name);
					}

                    AutoCraftTimer.OnSuccessfulCraft(from);
					//from.PlaySound( 0x57 );
				}

				if (num == 0)
				{
					num = craftSystem.PlayEndingEffect(from, false, true, toolBroken, endquality, makersMark, this);
				}

				bool queryFactionImbue = false;
				int availableSilver = 0;
				FactionItemDefinition def = null;
				Faction faction = null;

				if (item is IFactionItem)
				{
					def = FactionItemDefinition.Identify(item);

					if (def != null)
					{
						faction = Faction.Find(from);

						if (faction != null)
						{
							Town town = Town.FromRegion(from.Region);

							if (town != null && town.Owner == faction)
							{
								Container pack = from.Backpack;

								if (pack != null)
								{
									availableSilver = pack.GetAmount(typeof(Silver));

									if (availableSilver >= def.SilverCost)
									{
										queryFactionImbue = Faction.IsNearType(from, def.VendorType, 12);
									}
								}
							}
						}
					}
				}

				// TODO: Scroll imbuing

				if (queryFactionImbue)
				{
					from.SendGump(new FactionImbueGump(quality, item, from, craftSystem, tool, num, availableSilver, faction, def));
				}
				else if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
				{
					from.SendGump(new CraftGump(from, craftSystem, tool, num));
				}
				else if (num > 0)
				{
					from.SendLocalizedMessage(num);
				}
			}
			else if (!allRequiredSkills)
			{
				if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
				{
					from.SendGump(new CraftGump(from, craftSystem, tool, 1044153));
				}
				else
				{
					from.SendLocalizedMessage(1044153); // You don't have the required skills to attempt this item.
				}

                AutoCraftTimer.EndTimer(from);
			}
			else
			{
				ConsumeType consumeType = (UseAllRes ? ConsumeType.Half : ConsumeType.All);
				int resHue = 0;
				int maxAmount = 0;

				object message = null;

				// Not enough resource to craft it
				if (!ConsumeRes(from, typeRes, craftSystem, ref resHue, ref maxAmount, consumeType, ref message, true))
				{
					if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
					{
						from.SendGump(new CraftGump(from, craftSystem, tool, message));
					}
					else if (message is int && (int)message > 0)
					{
						from.SendLocalizedMessage((int)message);
					}
					else if (message is string)
					{
						from.SendMessage((string)message);
					}

                    AutoCraftTimer.EndTimer(from);

					return;
				}

				tool.UsesRemaining--;

				if (tool.UsesRemaining < 1)
				{
					toolBroken = true;
				}

				if (toolBroken)
				{
					tool.Delete();
				}

				// SkillCheck failed.
				int num = craftSystem.PlayEndingEffect(from, true, true, toolBroken, endquality, false, this);

				if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
				{
					from.SendGump(new CraftGump(from, craftSystem, tool, num));
				}
				else if (num > 0)
				{
					from.SendLocalizedMessage(num);
				}
			}
		}
Exemple #48
0
		public void CompleteCraft(int quality, bool makersMark, Mobile from, CraftSystem craftSystem, Type typeRes, BaseTool tool, CustomCraft customCraft, bool showGumps)
		{
			int badCraft = craftSystem.CanCraft(from, tool, m_Type);

            if (badCraft > 0)
            {
                if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
                    from.SendGump(new CraftGump(from, craftSystem, tool, badCraft));
                else
                    from.SendLocalizedMessage(badCraft);

                return;
            }

		    if (tool != null && !tool.Deleted && tool.UsesRemaining > 0)
		    {
		        if (tool.CraftSystem == DefBlacksmithy.CraftSystem)
		        {
		            if (from.FindItemOnLayer(Layer.OneHanded) != tool)
		            {
		                from.SendGump(new CraftGump(from, craftSystem, tool, string.Format("You must have your smith hammer equipped!")));
		                return;
		            }
		        }
		        else
		        {
		            if (!tool.IsChildOf(from.Backpack))
		            {
		                from.SendGump(new CraftGump(from, craftSystem, tool, string.Format("You must have your tool in your backpack!")));
		                return;
		            }
		        }
		    }
		    else
		    {
		        from.SendLocalizedMessage(badCraft);
		        return;
		    }


		    object checkMessage = null;
			int checkResHue = 0, checkMaxAmount = 0;
			
			// Not enough resource to craft it
			if ( !ConsumeRes( from, typeRes, craftSystem, ref checkResHue, ref checkMaxAmount, ConsumeType.None, ref checkMessage ) )
			{
                if (!tool.Deleted && tool.UsesRemaining > 0)
                    from.SendGump(new CraftGump(from, craftSystem, tool, checkMessage));
                else if (checkMessage is int && (int)checkMessage > 0)
                    from.SendLocalizedMessage((int)checkMessage);
                else if (checkMessage is string)
                    from.SendMessage((string)checkMessage);

				return;
			}
			if (!ConsumeAttributes(from, ref checkMessage, false))
			{
				if (!tool.Deleted && tool.UsesRemaining > 0)
                    from.SendGump(new CraftGump(from, craftSystem, tool, checkMessage));
				else if (checkMessage is int && (int)checkMessage > 0)
					from.SendLocalizedMessage((int)checkMessage);
				else if (checkMessage is string)
					from.SendMessage((string)checkMessage);

				return;
			}

			bool toolBroken = false;

			int ignored = 1;
			int endquality = 1;

			bool allRequiredSkills = true;

			if (CheckSkills(from, typeRes, craftSystem, ref ignored, ref allRequiredSkills))
			{
				// Resource
				int resHue = 0;
				int maxAmount = 0;

				object message = null;

				// Not enough resource to craft it
				if (!ConsumeRes(from, typeRes, craftSystem, ref resHue, ref maxAmount, ConsumeType.All, ref message))
				{
					if (!tool.Deleted && tool.UsesRemaining > 0)
                        from.SendGump(new CraftGump(from, craftSystem, tool, message));
					else if (message is int && (int)message > 0)
						from.SendLocalizedMessage((int)message);
					else if (message is string)
						from.SendMessage((string)message);

					return;
				}
			    if (!ConsumeAttributes(from, ref message, true))
			    {
			        if (!tool.Deleted && tool.UsesRemaining > 0)
			            from.SendGump(new CraftGump(from, craftSystem, tool, message));
			        else if (message is int && (int)message > 0)
			            from.SendLocalizedMessage((int)message);
			        else if (message is string)
			            from.SendMessage((string)message);

			        return;
			    }

			    if (tool is WeaversSpool)
                    tool.UsesRemaining--;

				if (craftSystem is DefBlacksmithy)
				{
					AncientSmithyHammer hammer = from.FindItemOnLayer(Layer.OneHanded) as AncientSmithyHammer;
					if (hammer != null && hammer != tool)
					{
						hammer.UsesRemaining--;
						if (hammer.UsesRemaining < 1)
							hammer.Delete();
					}
				}

                if (tool.UsesRemaining < 1)
                    toolBroken = true;

                if (toolBroken)
                    tool.Delete();

				int num = 0;

				Item item;
				if (customCraft != null)
					item = customCraft.CompleteCraft(out num);
				else if (typeof(MapItem).IsAssignableFrom(ItemType) && from.Map != Map.Trammel && from.Map != Map.Felucca)
				{
					item = new IndecipherableMap();
					from.SendLocalizedMessage(1070800); // The map you create becomes mysteriously indecipherable.
				}
				else
					item = Activator.CreateInstance(ItemType) as Item;

				if (item != null && !item.Deleted)
				{
                    if (craftSystem is DefCarpentry)
                    {
                        if (RetainsColorFrom(m_System, item.GetType()))
                        {
                            if (typeRes == typeof (OakLog))
                                item.Name = string.Format("Oak {0}", !string.IsNullOrEmpty(item.Name) ? item.Name.ToLower() : CliLoc.LocToString(item.LabelNumber).ToLower());
                            else if (typeRes == typeof (AshLog))
                                item.Name = string.Format("Ash {0}", !string.IsNullOrEmpty(item.Name) ? item.Name.ToLower() : CliLoc.LocToString(item.LabelNumber).ToLower());
                            else if (typeRes == typeof (YewLog))
                                item.Name = string.Format("Yew {0}", !string.IsNullOrEmpty(item.Name) ? item.Name.ToLower() : CliLoc.LocToString(item.LabelNumber).ToLower());
                            else if (typeRes == typeof (HeartwoodLog))
                                item.Name = string.Format("Heartwood {0}", !string.IsNullOrEmpty(item.Name) ? item.Name.ToLower() : CliLoc.LocToString(item.LabelNumber).ToLower());
                            else if (typeRes == typeof (BloodwoodLog))
                                item.Name = string.Format("Bloodwood {0}", !string.IsNullOrEmpty(item.Name) ? item.Name.ToLower() : CliLoc.LocToString(item.LabelNumber).ToLower());
                            else if (typeRes == typeof (FrostwoodLog))
                                item.Name = string.Format("Frostwood {0}", !string.IsNullOrEmpty(item.Name) ? item.Name.ToLower() : CliLoc.LocToString(item.LabelNumber).ToLower());
                            else if (typeRes == typeof(MahoganyLog))
                                item.Name = string.Format("Mahoganywood {0}", !string.IsNullOrEmpty(item.Name) ? item.Name.ToLower() : CliLoc.LocToString(item.LabelNumber).ToLower());
                            else if (typeRes == typeof(CedarLog))
                                item.Name = string.Format("Cedarwood {0}", !string.IsNullOrEmpty(item.Name) ? item.Name.ToLower() : CliLoc.LocToString(item.LabelNumber).ToLower());
                            else if (typeRes == typeof(WillowLog))
                                item.Name = string.Format("Willowwood {0}", !string.IsNullOrEmpty(item.Name) ? item.Name.ToLower() : CliLoc.LocToString(item.LabelNumber).ToLower());
                            else if (typeRes == typeof(MystWoodLog))
                                item.Name = string.Format("Mystwood {0}", !string.IsNullOrEmpty(item.Name) ? item.Name.ToLower() : CliLoc.LocToString(item.LabelNumber).ToLower());
                        }
                    }

					if (item is ICraftable)
					{
                        if (item.Hue == 0)
                            item.Hue = resHue;

						endquality = ((ICraftable)item).OnCraft(quality, makersMark, from, craftSystem, typeRes, tool, this, resHue);
					}
					else if (item.Hue == 0)
					{
						item.Hue = resHue;

					    //Flag all high quality non ICraftable with a makers mark in the string
						if (craftSystem.MarkOption && makersMark && quality == 2 && from.Skills[craftSystem.MainSkill].Base >= 100.0)
						{
							endquality = quality;

						    item.Name = string.Format("{0} crafted by {1}", !string.IsNullOrEmpty(item.Name) ? item.Name : CliLoc.LocToString(item.LabelNumber), from.Name);
						}
					}

					if (maxAmount > 0)
						if (!item.Stackable && item is IUsesRemaining)
							((IUsesRemaining)item).UsesRemaining *= maxAmount;
						else
							item.Amount = maxAmount;

                    #region Add to pack or ground if overweight
                    //Taran: Check to see if player is overweight. If they are and the item drops to the
                    //ground then a check is made to see if it can be stacked. If it can't and  more than 
                    //20 items of the same type exist in the same tile then the last item gets removed. This 
                    //check is made so thousands of items can't exist in 1 tile and crash people in the same area.
                    if (from.AddToBackpack(item))
                    {
                        if (item is SpellScroll)
                            from.SendAsciiMessage("You put the {0} scroll in your pack.", item.Name ?? CliLoc.LocToString(item.LabelNumber));
                        else
                            from.SendAsciiMessage("You put the {0} in your pack.", item.Name ?? CliLoc.LocToString(item.LabelNumber));
                    }
                    else if (!item.Deleted)
                    {
                        IPooledEnumerable eable = from.Map.GetItemsInRange(from.Location, 0);
                        int amount = 0;
                        Item toRemove = null;

                        foreach (Item i in eable)
                        {
                            if (i != item && i.ItemID == item.ItemID)
                            {
                                if (i.StackWith(from, item, false))
                                {
                                    toRemove = item;
                                    break;
                                }
                                
                                amount++;
                            }
                        }

                        from.SendAsciiMessage("You are overweight and put the {0} on the ground.", item.Name ?? CliLoc.LocToString(item.LabelNumber));

                        if (toRemove != null)
                            toRemove.Delete();

                        else if (amount >= 5 && amount < 20)
                            from.LocalOverheadMessage(MessageType.Regular, 906, true, string.Format("{0} identical items on the ground detected, no more than 20 is allowed!", amount));

                        else if (amount >= 20)
                        {
                            from.LocalOverheadMessage(MessageType.Regular, 906, true, "Too many identical items on the ground, removing!");
                            item.Delete();
                        }

                        eable.Free();
                    }
                    #endregion

                    if (from.AccessLevel > AccessLevel.Player)
						CommandLogging.WriteLine(from, "Crafting {0} with craft system {1}", CommandLogging.Format(item), craftSystem.GetType().Name);

				}

				if (num == 0)
					num = craftSystem.PlayEndingEffect(from, false, true, toolBroken, endquality, makersMark, this);

				bool queryFactionImbue = false;
				int availableSilver = 0;
				FactionItemDefinition def = null;
				Faction faction = null;

				if (item is IFactionItem)
				{
					def = FactionItemDefinition.Identify(item);

					if (def != null)
					{
						faction = Faction.Find(from);

						if (faction != null)
						{
							Town town = Town.FromRegion(from.Region);

							if (town != null && town.Owner == faction)
							{
								Container pack = from.Backpack;

								if (pack != null)
								{
									availableSilver = pack.GetAmount(typeof(Silver));

									if (availableSilver >= def.SilverCost)
										queryFactionImbue = Faction.IsNearType(from, def.VendorType, 12);
								}
							}
						}
					}
				}

				// TODO: Scroll imbuing

				if (queryFactionImbue)
					from.SendGump(new FactionImbueGump(quality, item, from, craftSystem, tool, num, availableSilver, faction, def));
				else if (!tool.Deleted && tool.UsesRemaining > 0)
					from.SendGump(new CraftGump(from, craftSystem, tool, num));
				else if (num > 0)
					from.SendLocalizedMessage(num);
			}
			else if (!allRequiredSkills)
				if (!tool.Deleted && tool.UsesRemaining > 0)
					from.SendGump(new CraftGump(from, craftSystem, tool, 1044153));
				else
					from.SendLocalizedMessage(1044153); // You don't have the required skills to attempt this item.
			else
			{
				ConsumeType consumeType = (UseAllRes ? ConsumeType.Half : ConsumeType.All);
				int resHue = 0;
				int maxAmount = 0;

				object message = null;

				// Not enough resource to craft it
				if (!ConsumeRes(from, typeRes, craftSystem, ref resHue, ref maxAmount, consumeType, ref message, true))
				{
					if (!tool.Deleted && tool.UsesRemaining > 0)
						from.SendGump(new CraftGump(from, craftSystem, tool, message));
					else if (message is int && (int)message > 0)
						from.SendLocalizedMessage((int)message);
					else if (message is string)
						from.SendMessage((string)message);

					return;
				}

				//tool.UsesRemaining--;

                if (tool is WeaversSpool)
                    tool.UsesRemaining--;

				if (tool.UsesRemaining < 1)
					toolBroken = true;

				if (toolBroken)
					tool.Delete();

				// SkillCheck failed.
				int num = craftSystem.PlayEndingEffect(from, true, true, toolBroken, endquality, false, this);

				if (!tool.Deleted && tool.UsesRemaining > 0)
                    from.SendGump(new CraftGump(from, craftSystem, tool, num));
				else if (num > 0)
					from.SendLocalizedMessage(num);
			}
		}
Exemple #49
0
		public static EnhanceResult Invoke( Mobile from, CraftSystem craftSystem, BaseTool tool, Item item, CraftResource resource, Type resType, ref object resMessage )
		{
			if ( item == null )
				return EnhanceResult.BadItem;

			if ( !item.IsChildOf( from.Backpack ) )
				return EnhanceResult.NotInBackpack;

			if ( !(item is BaseArmor) && !(item is BaseWeapon) )
				return EnhanceResult.BadItem;

			if ( item is IArcaneEquip )
			{
				IArcaneEquip eq = (IArcaneEquip)item;
				if ( eq.IsArcane )
					return EnhanceResult.BadItem;
			}

			if ( CraftResources.IsStandard( resource ) )
				return EnhanceResult.BadResource;
			
			int num = craftSystem.CanCraft( from, tool, item.GetType() );
			
			if ( num > 0 )
			{
				resMessage = num;
				return EnhanceResult.None;
			}

			CraftItem craftItem = craftSystem.CraftItems.SearchFor( item.GetType() );

			if ( craftItem == null || craftItem.Resources.Count == 0 )
				return EnhanceResult.BadItem;

			bool allRequiredSkills = false;
			if( craftItem.GetSuccessChance( from, resType, craftSystem, false, ref allRequiredSkills ) <= 0.0 )
				return EnhanceResult.NoSkill;

			CraftResourceInfo info = CraftResources.GetInfo( resource );

			if ( info == null || info.ResourceTypes.Length == 0 )
				return EnhanceResult.BadResource;

			CraftAttributeInfo attributes = info.AttributeInfo;

			if ( attributes == null )
				return EnhanceResult.BadResource;

			int resHue = 0, maxAmount = 0;

			if ( !craftItem.ConsumeRes( from, resType, craftSystem, ref resHue, ref maxAmount, ConsumeType.None, ref resMessage ) )
				return EnhanceResult.NoResources;

			if ( craftSystem is DefBlacksmithy )
			{
				AncientSmithyHammer hammer = from.FindItemOnLayer( Layer.OneHanded ) as AncientSmithyHammer;
				if ( hammer != null )
				{
					hammer.UsesRemaining--;
					if ( hammer.UsesRemaining < 1 )
						hammer.Delete();
				}
			}

			int phys = 0, fire = 0, cold = 0, pois = 0, nrgy = 0;
			int dura = 0, luck = 0, lreq = 0, dinc = 0;
			int baseChance = 0;

			bool physBonus = false;
			bool fireBonus = false;
			bool coldBonus = false;
			bool nrgyBonus = false;
			bool poisBonus = false;
			bool duraBonus = false;
			bool luckBonus = false;
			bool lreqBonus = false;
			bool dincBonus = false;

			if ( item is BaseWeapon )
			{
				BaseWeapon weapon = (BaseWeapon)item;

				if ( !CraftResources.IsStandard( weapon.Resource ) )
					return EnhanceResult.AlreadyEnhanced;

				baseChance = 20;

				dura = weapon.MaxHitPoints;
				luck = weapon.Attributes.Luck;
				lreq = weapon.WeaponAttributes.LowerStatReq;
				dinc = weapon.Attributes.WeaponDamage;

				fireBonus = ( attributes.WeaponFireDamage > 0 );
				coldBonus = ( attributes.WeaponColdDamage > 0 );
				nrgyBonus = ( attributes.WeaponEnergyDamage > 0 );
				poisBonus = ( attributes.WeaponPoisonDamage > 0 );

				duraBonus = ( attributes.WeaponDurability > 0 );
				luckBonus = ( attributes.WeaponLuck > 0 );
				lreqBonus = ( attributes.WeaponLowerRequirements > 0 );
				dincBonus = ( dinc > 0 );
			}
			else
			{
				BaseArmor armor = (BaseArmor)item;

				if ( !CraftResources.IsStandard( armor.Resource ) )
					return EnhanceResult.AlreadyEnhanced;

				baseChance = 20;

				phys = armor.PhysicalResistance;
				fire = armor.FireResistance;
				cold = armor.ColdResistance;
				pois = armor.PoisonResistance;
				nrgy = armor.EnergyResistance;

				dura = armor.MaxHitPoints;
				luck = armor.Attributes.Luck;
				lreq = armor.ArmorAttributes.LowerStatReq;

				physBonus = ( attributes.ArmorPhysicalResist > 0 );
				fireBonus = ( attributes.ArmorFireResist > 0 );
				coldBonus = ( attributes.ArmorColdResist > 0 );
				nrgyBonus = ( attributes.ArmorEnergyResist > 0 );
				poisBonus = ( attributes.ArmorPoisonResist > 0 );

				duraBonus = ( attributes.ArmorDurability > 0 );
				luckBonus = ( attributes.ArmorLuck > 0 );
				lreqBonus = ( attributes.ArmorLowerRequirements > 0 );
				dincBonus = false;
			}

			int skill = from.Skills[craftSystem.MainSkill].Fixed / 10;

			if ( skill >= 100 )
				baseChance -= (skill - 90) / 10;

			EnhanceResult res = EnhanceResult.Success;

			if ( physBonus )
				CheckResult( ref res, baseChance + phys );

			if ( fireBonus )
				CheckResult( ref res, baseChance + fire );

			if ( coldBonus )
				CheckResult( ref res, baseChance + cold );

			if ( nrgyBonus )
				CheckResult( ref res, baseChance + nrgy );

			if ( poisBonus )
				CheckResult( ref res, baseChance + pois );

			if ( duraBonus )
				CheckResult( ref res, baseChance + (dura / 40) );

			if ( luckBonus )
				CheckResult( ref res, baseChance + 10 + (luck / 2) );

			if ( lreqBonus )
				CheckResult( ref res, baseChance + (lreq / 4) );

			if ( dincBonus )
				CheckResult( ref res, baseChance + (dinc / 4) );

			switch ( res )
			{
				case EnhanceResult.Broken:
				{
					if ( !craftItem.ConsumeRes( from, resType, craftSystem, ref resHue, ref maxAmount, ConsumeType.Half, ref resMessage ) )
						return EnhanceResult.NoResources;

					item.Delete();
					break;
				}
				case EnhanceResult.Success:
				{
					if ( !craftItem.ConsumeRes( from, resType, craftSystem, ref resHue, ref maxAmount, ConsumeType.All, ref resMessage ) )
						return EnhanceResult.NoResources;

					if( item is BaseWeapon )
					{
						BaseWeapon w = (BaseWeapon)item;

						w.Resource = resource;

						int hue = w.GetElementalDamageHue();
						if( hue > 0 )
							w.Hue = hue;
					}
					else if( item is BaseArmor )	//Sanity
					{
						((BaseArmor)item).Resource = resource;
					}

					break;
				}
				case EnhanceResult.Failure:
				{
					if ( !craftItem.ConsumeRes( from, resType, craftSystem, ref resHue, ref maxAmount, ConsumeType.Half, ref resMessage ) )
						return EnhanceResult.NoResources;

					break;
				}
			}

			return res;
		}