Exemplo n.º 1
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);
        }
Exemplo n.º 2
0
            protected override void OnTarget(Mobile from, object targeted)
            {
                if (targeted is LockableContainer)
                {
                    LockableContainer lc = targeted as LockableContainer;

                    if (lc.Locked)
                    {
                        from.EndAction(typeof(CraftSystem));

                        from.SendGump(new CraftGump(from, m_CraftSystem, m_Tool, 502943));                             // You can only trap an unlocked object.
                    }
                    else if (lc.IsLockedDown)
                    {
                        from.EndAction(typeof(CraftSystem));

                        from.SendGump(new CraftGump(from, m_CraftSystem, m_Tool, 502944));                             // You cannot trap this item because it is locked down.
                    }
                    else if (lc.TrapType != TrapType.None)
                    {
                        from.EndAction(typeof(CraftSystem));

                        from.SendGump(new CraftGump(from, m_CraftSystem, m_Tool, 502945));                             // You can only place one trap on an object at a time.
                    }
                    else if (lc.RootParent != from)
                    {
                        from.EndAction(typeof(CraftSystem));

                        from.SendGump(new CraftGump(from, m_CraftSystem, m_Tool, 502946));                             // That belongs to someone else.
                    }
                    else
                    {
                        object message = null;

                        int maxAmount = 0;

                        bool AllRequiredSkills = true;

                        if (m_craftItem.ConsumeRes(from, m_typeRes, m_CraftSystem, ref m_resHue, ref maxAmount, ConsumeType.All, ref message))
                        {
                            double chance = m_craftItem.GetSuccessChance(from, m_typeRes, m_CraftSystem, true, ref AllRequiredSkills);

                            if (AllRequiredSkills)
                            {
                                if (chance > Utility.RandomDouble())
                                {
                                    lc.Enabled  = true;
                                    lc.TrapType = m_Type;

                                    switch (m_Type)
                                    {
                                    case TrapType.DartTrap:
                                        lc.TrapPower = Utility.RandomMinMax(50, 70);
                                        break;

                                    case TrapType.ExplosionTrap:
                                        lc.TrapPower = Utility.RandomMinMax(30, 50);
                                        break;
                                        // at OSI Poison Trap possible no causes direct damage, only poison effect
                                    }

                                    bool toolBroken = false;

                                    m_Tool.UsesRemaining--;

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

                                    if (toolBroken)
                                    {
                                        m_Tool.Delete();

                                        from.SendLocalizedMessage(1044038);                                           // You have worn out your tool!

                                        from.SendLocalizedMessage(1005639);                                           // Trap is disabled until you lock the chest.
                                    }

                                    if (!toolBroken)
                                    {
                                        from.SendGump(new CraftGump(from, m_CraftSystem, m_Tool, 1005639));                                             // Trap is disabled until you lock the chest.
                                    }
                                }
                                else
                                {
                                    from.EndAction(typeof(CraftSystem));

                                    from.SendGump(new CraftGump(from, m_CraftSystem, m_Tool, 1044043));                                         // You failed to create the item, and some of your materials are lost.
                                }
                            }
                            else
                            {
                                from.EndAction(typeof(CraftSystem));

                                from.SendGump(new CraftGump(from, m_CraftSystem, m_Tool, 1044153));                                     // You don't have the required skills to attempt this item.
                            }
                        }
                        else
                        {
                            from.EndAction(typeof(CraftSystem));

                            from.SendGump(new CraftGump(from, m_CraftSystem, m_Tool, 1044253));                                 // You don't have the components needed to make that.
                        }
                    }
                }
                else
                {
                    from.SendGump(new CraftGump(from, m_CraftSystem, m_Tool, 1005638));                         // You can only trap lockable chests.
                }

                m_Trap.Delete();
            }