#include "inc_item_tools"
void main()
    {
    //------------------------SET VARIABLES-----------------------------
    object oPC = GetLastDisturbed();
    int iType,iEnc,iEncTemp,iPrice,iValue,i,iSkill,iPassed,iMW,iWeapon,iArmor,iTemp,iHFort,iBurst,iUnlim;
    int iSpell = -1;
    int iSpell2 = -1;
    int iSpell3 = -1;
    int iCasterLevel = -1;
    int iAlign = -1;
    int iBane = -1;
    int iSpecial = -1;
    int iGold = GetGold(OBJECT_SELF);
    int iXP = GetXP(oPC);
    int iXPCost,iXPAfterCraft;
    itemproperty ipItem;
    object oCraftable,oMaterial,oObject;
    string sMaterial;
    object oSound = GetObjectByTag("Tavern_Forge_Sound");
    int iDC = 20;
    if (GetHasFeat(FEAT_STONECUNNING,oPC))
        iDC = 18;
    // -----------------Record items in container------------------------
    oObject = GetFirstItemInInventory(OBJECT_SELF);
    while(GetIsObjectValid(oObject))
        {
        iType = GetBaseItemType(oObject);
        iWeapon = GetIsWeapon(oObject);
        iArmor = GetIsArmor(oObject);
        if (iSkill && (iWeapon || iArmor))
            return; //Can only enchant 1 item at a time.
        if (iWeapon && !iSkill)
            {
            if (GetIsAmmo(oObject)) // DUE TO SCRIPTING LIMITATIONS AMMUNITION CAN NOT BE ENCHANTED. ADD TO THINGS TO DO LIST THIS WILL BE UGLY!
                return;
            iSkill = SKILL_CRAFT_WEAPON;
            oCraftable = oObject;
            }
        else if (iArmor && !iSkill)
            {
            iSkill = SKILL_CRAFT_ARMOR;
            oCraftable = oObject;
            }
        else if (iType == BASE_ITEM_CRAFTMATERIALMED
              || iType == BASE_ITEM_CRAFTMATERIALSML)
            oMaterial = oObject;
        oObject = GetNextItemInInventory(OBJECT_SELF);
        }
    if (!iSkill)
        return; // Not an armor or weapon being crafted shut down
//------------------------ Set New Variables based on contents-----------
    int iLauncher = GetIsLauncher(oCraftable);
    int iIsMasterWork = GetLocalInt(oCraftable,"MW");
    iEnc = GetLocalInt(oCraftable,"Enc");
    if (iEnc == 20) return;
    else if (iEnc == 0) iEnc = GetEnchantmentBonus(oCraftable);
    iEncTemp = GetEnchantmentBonus(oCraftable);
    iValue = GetTotalEnchantmentValue(oCraftable);
    if (GetIsObjectValid(oMaterial))
        sMaterial = GetTag(oMaterial);
// -----------------------------BEGIN RECIPES---------------------------------
// -----------    The Recipes should be listed from complex to easiest.-------
    if (GetIsObjectValid(oCraftable))
        {
        if (iIsMasterWork || iEncTemp >= 1)
            {
            if (GetIsObjectValid(oMaterial))
                {
                if (iArmor)
                    {
                    if (GetIsShield(oCraftable))//Shields
                        {
                        if (sMaterial == "bashmat")
                            {
                            iSpell = SPELL_BULLS_STRENGTH;
                            iCasterLevel = 8;
                            i = 1;
                            ipItem = ItemPropertyBonusFeat(IP_CONST_FEAT_KNOCKDOWN);
                            }
                        else if (sMaterial == "blindmat")
                            {
                            iSpell = SPELL_BLINDNESS_AND_DEAFNESS;
                            iSpell2 = SPELL_SEARING_LIGHT;
                            iCasterLevel = 7;
                            i = 1;
                            ipItem = ItemPropertyOnHitCastSpell(SPELL_BLINDNESS_AND_DEAFNESS,4);
                            }
                        else if (sMaterial == "lfortmat")
                            {
                            iSpell = -1;
                            iCasterLevel = -1;
                            i = 1;
                            ipItem = ItemPropertyImmunityMisc(IP_CONST_IMMUNITYMISC_BACKSTAB);
                            }
                        else if (sMaterial == "arrdefmat")
                            {
                            iSpell = SPELL_SHIELD;
                            iCasterLevel = 5;
                            i = 2;
                            ipItem = ItemPropertyDamageResistance(IP_CONST_DAMAGETYPE_PIERCING,IP_CONST_DAMAGESOAK_5_HP);
                            }
                        else if (sMaterial == "arrdefmat2")
                            {
                            iSpell = SPELL_SHIELD;
                            iCasterLevel = 12;
                            i = 2;
                            ipItem = ItemPropertyDamageResistance(IP_CONST_DAMAGETYPE_PIERCING,IP_CONST_DAMAGESOAK_10_HP);
                            }
                        else if (sMaterial == "spell14mat")
                            {
                            iSpell = SPELL_SPELL_RESISTANCE;
                            iCasterLevel = 15;
                            i = 2;
                            ipItem = ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_14);
                            }
                        else if (sMaterial == "ghostmat")
                            {
                            iSpell = SPELL_TRUE_SEEING;
                            iCasterLevel = 5;
                            i = 3;
                            ipItem = ItemPropertyTrueSeeing();
                            }
                        else if (sMaterial == "mfortmat")
                            {
                            iSpell = -1;
                            iCasterLevel = -1;
                            i = 3;
                            ipItem = ItemPropertyImmunityMisc(IP_CONST_IMMUNITYMISC_CRITICAL_HITS);
                            }
                        else if (sMaterial == "acidmat")
                            {
                            iSpell = SPELL_RESIST_ELEMENTS;
                            iCasterLevel = 5;
                            i = 3;
                            ipItem = ItemPropertyDamageResistance(IP_CONST_DAMAGETYPE_ACID,IP_CONST_DAMAGERESIST_10);
                            }
                        else if (sMaterial == "coldmat")
                            {
                            iSpell = SPELL_RESIST_ELEMENTS;
                            iCasterLevel = 5;
                            i = 3;
                            ipItem = ItemPropertyDamageResistance(IP_CONST_DAMAGETYPE_COLD,IP_CONST_DAMAGERESIST_10);
                            }
                        else if (sMaterial == "firemat")
                            {
                            iSpell = SPELL_RESIST_ELEMENTS;
                            iCasterLevel = 5;
                            i = 3;
                            ipItem = ItemPropertyDamageResistance(IP_CONST_DAMAGETYPE_FIRE,IP_CONST_DAMAGERESIST_10);
                            }
                        else if (sMaterial == "elecmat")
                            {
                            iSpell = SPELL_RESIST_ELEMENTS;
                            iCasterLevel = 5;
                            i = 3;
                            ipItem = ItemPropertyDamageResistance(IP_CONST_DAMAGETYPE_ELECTRICAL,IP_CONST_DAMAGERESIST_10);
                            }
                        else if (sMaterial == "sonicmat")
                            {
                            iSpell = SPELL_RESIST_ELEMENTS;
                            iCasterLevel = 5;
                            i = 3;
                            ipItem = ItemPropertyDamageResistance(IP_CONST_DAMAGETYPE_SONIC,IP_CONST_DAMAGERESIST_10);
                            }
                        else if (sMaterial == "spell16mat")
                            {
                            iSpell = SPELL_SPELL_RESISTANCE;
                            iCasterLevel = 15;
                            i = 3;
                            ipItem = ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_16);
                            }
                        else if (sMaterial == "spell18mat")
                            {
                            iSpell = SPELL_SPELL_RESISTANCE;
                            iCasterLevel = 15;
                            i = 4;
                            ipItem = ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_18);
                            }
                        else if (sMaterial == "hfortmat")
                            {
                            iSpell = -1;
                            iCasterLevel = -1;
                            i = 5;
                            iHFort = TRUE;
                            }
                        else if (sMaterial == "reflecmat")
                            {
                            iSpell = SPELL_SPELL_MANTLE;
                            iCasterLevel = 14;
                            i = 5;
                            ipItem = ItemPropertyCastSpell(IP_CONST_CASTSPELL_SPELL_MANTLE_13,IP_CONST_CASTSPELL_NUMUSES_1_USE_PER_DAY);
                            }
                        else if (sMaterial == "spell20mat")
                            {
                            iSpell = SPELL_SPELL_RESISTANCE;
                            iCasterLevel = 15;
                            i = 5;
                            ipItem = ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_20);
                            }
                        }
                    else // Armor
                        {
                        if (sMaterial == "lfortmat")
                            {
                            iSpell = -1;
                            iCasterLevel = -1;
                            i = 1;
                            ipItem = ItemPropertyImmunityMisc(IP_CONST_IMMUNITYMISC_BACKSTAB);
                            }
                        else if (sMaterial == "lglammat")
                            {
                            i = 1;
                            switch(Random(7)+1)
                                {
                                case 1: {iTemp = IP_CONST_LIGHTCOLOR_BLUE;break;}
                                case 2: {iTemp = IP_CONST_LIGHTCOLOR_GREEN;break;}
                                case 3: {iTemp = IP_CONST_LIGHTCOLOR_ORANGE;break;}
                                case 4: {iTemp = IP_CONST_LIGHTCOLOR_PURPLE;break;}
                                case 5: {iTemp = IP_CONST_LIGHTCOLOR_RED;break;}
                                case 6: {iTemp = IP_CONST_LIGHTCOLOR_WHITE;break;}
                                case 7: {iTemp = IP_CONST_LIGHTCOLOR_YELLOW;break;}
                                };
                            ipItem = ItemPropertyLight(IP_CONST_LIGHTBRIGHTNESS_BRIGHT,iTemp);
                            }
                        else if (sMaterial == "slickmat")
                            {
                            iSpell = SPELL_GREASE;
                            iCasterLevel = 4;
                            i = 1;
                            ipItem = ItemPropertySkillBonus(SKILL_TUMBLE,10);
                            }
                        else if (sMaterial == "shadowmat")
                            {
                            iSpell = SPELL_INVISIBILITY;
                            iCasterLevel = 5;
                            i = 1;
                            ipItem = ItemPropertySkillBonus(SKILL_HIDE,10);
                            }
                        else if (sMaterial == "silentmat")
                            {
                            iSpell = SPELL_SILENCE;
                            iCasterLevel = 5;
                            i = 1;
                            ipItem = ItemPropertySkillBonus(SKILL_MOVE_SILENTLY,10);
                            }
                        else if (sMaterial == "spell14mat")
                            {
                            iSpell = SPELL_SPELL_RESISTANCE;
                            iCasterLevel = 15;
                            i = 2;
                            ipItem = ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_14);
                            }
                        else if (sMaterial == "ghostmat")
                            {
                            iSpell = SPELL_TRUE_SEEING;
                            iCasterLevel = 5;
                            i = 3;
                            ipItem = ItemPropertyTrueSeeing();
                            }
                        else if (sMaterial == "invulmat")
                            {
                            iSpell = SPELL_STONESKIN;
                            iCasterLevel = 18;
                            i = 3;
                            ipItem = ItemPropertyDamageReduction(IP_CONST_DAMAGEREDUCTION_1,IP_CONST_DAMAGESOAK_5_HP);
                            }
                        else if (sMaterial == "mfortmat")
                            {
                            iSpell = -1;
                            iCasterLevel = -1;
                            i = 3;
                            ipItem = ItemPropertyImmunityMisc(IP_CONST_IMMUNITYMISC_CRITICAL_HITS);
                            }
                        else if (sMaterial == "spell16mat")
                            {
                            iSpell = SPELL_SPELL_RESISTANCE;
                            iCasterLevel = 15;
                            i = 3;
                            ipItem = ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_16);
                            }
                        else if (sMaterial == "acidmat")
                            {
                            iSpell = SPELL_RESIST_ELEMENTS;
                            iCasterLevel = 5;
                            i = 3;
                            ipItem = ItemPropertyDamageResistance(IP_CONST_DAMAGETYPE_ACID,IP_CONST_DAMAGERESIST_10);
                            }
                        else if (sMaterial == "coldmat")
                            {
                            iSpell = SPELL_RESIST_ELEMENTS;
                            iCasterLevel = 5;
                            i = 3;
                            ipItem = ItemPropertyDamageResistance(IP_CONST_DAMAGETYPE_COLD,IP_CONST_DAMAGERESIST_10);
                            }
                        else if (sMaterial == "firemat")
                            {
                            iSpell = SPELL_RESIST_ELEMENTS;
                            iCasterLevel = 5;
                            i = 3;
                            ipItem = ItemPropertyDamageResistance(IP_CONST_DAMAGETYPE_FIRE,IP_CONST_DAMAGERESIST_10);
                            }
                        else if (sMaterial == "elecmat")
                            {
                            iSpell = SPELL_RESIST_ELEMENTS;
                            iCasterLevel = 5;
                            i = 3;
                            ipItem = ItemPropertyDamageResistance(IP_CONST_DAMAGETYPE_ELECTRICAL,IP_CONST_DAMAGERESIST_10);
                            }
                        else if (sMaterial == "sonicmat")
                            {
                            iSpell = SPELL_RESIST_ELEMENTS;
                            iCasterLevel = 5;
                            i = 3;
                            ipItem = ItemPropertyDamageResistance(IP_CONST_DAMAGETYPE_SONIC,IP_CONST_DAMAGERESIST_10);
                            }
                        else if (sMaterial == "spell18mat")
                            {
                            iSpell = SPELL_SPELL_RESISTANCE;
                            iCasterLevel = 15;
                            i = 4;
                            ipItem = ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_18);
                            }
                        else if (sMaterial == "ethmat")
                            {
                            iSpell = SPELL_ETHEREALNESS;
                            iCasterLevel = 15;
                            i = 5;
                            ipItem = ItemPropertyCastSpell(SPELL_ETHEREALNESS,IP_CONST_CASTSPELL_NUMUSES_1_USE_PER_DAY);
                            }
                        else if (sMaterial == "hfortmat")
                            {
                            iSpell = -1;
                            iCasterLevel = -1;
                            i = 5;
                            iHFort = TRUE;
                            }
                        else if (sMaterial == "spell20mat")
                            {
                            iSpell = SPELL_SPELL_RESISTANCE;
                            iCasterLevel = 15;
                            i = 5;
                            ipItem = ItemPropertyBonusSpellResistance(IP_CONST_SPELLRESISTANCEBONUS_20);
                            }
                        }
                    }
                else // Weapons
                    {
                    if (iLauncher)//Ranged weapons
                        {
                        if (sMaterial == "unlimmat")
                            {
                            i = 1;
                            ipItem = ItemPropertyUnlimitedAmmo(IP_CONST_UNLIMITEDAMMO_BASIC);
                            }
                        else if (sMaterial == "acidmat2")
                            {
                            iSpell = SPELL_MELFS_ACID_ARROW;
                            iSpell2 = SPELL_MESTILS_ACID_SHEATH;
                            iCasterLevel = 8;
                            i = 1;
                            iSpecial = IP_CONST_DAMAGETYPE_ACID;
                            ipItem = ItemPropertyCastSpell(IP_CONST_CASTSPELL_UNIQUE_POWER_SELF_ONLY,IP_CONST_CASTSPELL_NUMUSES_UNLIMITED_USE);
                            }
                        else if (sMaterial == "firemat2")
                            {
                            iSpell = SPELL_FIREBALL;
                            iSpell2 = SPELL_FLAME_WEAPON;
                            iSpell3 = SPELL_FLAME_STRIKE;
                            iCasterLevel = 10;
                            i = 1;
                            iSpecial = IP_CONST_DAMAGETYPE_FIRE;
                            ipItem = ItemPropertyCastSpell(IP_CONST_CASTSPELL_UNIQUE_POWER_SELF_ONLY,IP_CONST_CASTSPELL_NUMUSES_UNLIMITED_USE);
                            }
                        else if (sMaterial == "elecmat2")
                            {
                            iSpell = SPELL_CALL_LIGHTNING;
                            iSpell2 = SPELL_LIGHTNING_BOLT;
                            iCasterLevel = 8;
                            i = 1;
                            iSpecial = IP_CONST_DAMAGETYPE_ELECTRICAL;
                            ipItem = ItemPropertyCastSpell(IP_CONST_CASTSPELL_UNIQUE_POWER_SELF_ONLY,IP_CONST_CASTSPELL_NUMUSES_UNLIMITED_USE);
                            }
                        else if (sMaterial == "coldmat2")
                            {
                            iSpell = SPELL_ICE_STORM;
                            iCasterLevel = 8;
                            i = 1;
                            iSpecial = IP_CONST_DAMAGETYPE_COLD;
                            ipItem = ItemPropertyCastSpell(IP_CONST_CASTSPELL_UNIQUE_POWER_SELF_ONLY,IP_CONST_CASTSPELL_NUMUSES_UNLIMITED_USE);
                            }

                        else if (sMaterial == "firemat3")
                            {
                            iSpell = SPELL_FIREBALL;
                            iSpell2 = SPELL_FLAME_WEAPON;
                            iSpell3 = SPELL_FLAME_STRIKE;
                            iCasterLevel = 12;
                            i = 2;
                            ipItem = ItemPropertyUnlimitedAmmo(IP_CONST_UNLIMITEDAMMO_1D6FIRE);
                            }
                        else if (sMaterial == "coldmat3")
                            {
                            iSpell = SPELL_ICE_STORM;
                            iCasterLevel = 10;
                            i = 2;
                            ipItem = ItemPropertyUnlimitedAmmo(IP_CONST_UNLIMITEDAMMO_1D6COLD);
                            }
                        else if (sMaterial == "elecmat3")
                            {
                            iSpell = SPELL_CALL_LIGHTNING;
                            iSpell2 = SPELL_LIGHTNING_BOLT;
                            iCasterLevel = 10;
                            i = 2;
                            ipItem = ItemPropertyUnlimitedAmmo(IP_CONST_UNLIMITEDAMMO_1D6LIGHT);
                            }
                        else if (sMaterial == "banemat")
                            {
                            iSpell = SPELL_SUMMON_CREATURE_I;
                            iCasterLevel = 8;
                            i = 2;
                            iBane = GetBaneRace();
                            ipItem = ItemPropertyEnhancementBonusVsRace(iBane,iEncTemp+2);
                            }
                        else if (sMaterial == "holymat")
                            {
                            if (GetAlignmentGoodEvil(oPC) != ALIGNMENT_GOOD)
                                {
                                FloatingTextStringOnCreature("Can only be placed by a person of good alignment.",oPC,FALSE);
                                return;
                                }
                            if (!GetHasFeat(FEAT_SMITE_EVIL))
                                {
                                FloatingTextStringOnCreature("Can only be placed by a person with the smite evil feat.",oPC,FALSE);
                                return;
                                }
                            iCasterLevel = 7;
                            i = 2;
                            ipItem = ItemPropertyDamageBonusVsAlign(IP_CONST_ALIGNMENTGROUP_EVIL,IP_CONST_DAMAGETYPE_DIVINE,IP_CONST_DAMAGEBONUS_2d6);
                            iAlign = IP_CONST_ALIGNMENTGROUP_GOOD;
                            }
                        else if (sMaterial == "unholymat")
                            {
                            if (GetAlignmentGoodEvil(oPC) != ALIGNMENT_EVIL)
                                {
                                FloatingTextStringOnCreature("Can only be placed by a person of evil alignment.",oPC,FALSE);
                                return;
                                }
                            iSpell = SPELL_UNHOLY_AURA;
                            iCasterLevel = 7;
                            i = 2;
                            ipItem = ItemPropertyDamageBonusVsAlign(IP_CONST_ALIGNMENTGROUP_GOOD,IP_CONST_DAMAGETYPE_DIVINE,IP_CONST_DAMAGEBONUS_2d6);
                            iAlign = IP_CONST_ALIGNMENTGROUP_EVIL;
                            }
                        else if (sMaterial == "lawfulmat")
                            {
                            if (GetAlignmentLawChaos(oPC) != ALIGNMENT_LAWFUL)
                                {
                                FloatingTextStringOnCreature("Can only be placed by a person of lawful alignment.",oPC,FALSE);
                                return;
                                }
                            iSpell = SPELL_SHIELD_OF_LAW;
                            iCasterLevel = 7;
                            i = 2;
                            ipItem = ItemPropertyDamageBonusVsAlign(IP_CONST_ALIGNMENTGROUP_CHAOTIC,IP_CONST_DAMAGETYPE_DIVINE,IP_CONST_DAMAGEBONUS_2d6);
                            iAlign = IP_CONST_ALIGNMENTGROUP_LAWFUL;
                            }
                        else if (sMaterial == "chaosmat")
                            {
                            if (GetAlignmentLawChaos(oPC) != ALIGNMENT_CHAOTIC)
                                {
                                FloatingTextStringOnCreature("Can only be placed by a person of chaotic alignment.",oPC,FALSE);
                                return;
                                }
                            iSpell = SPELL_CLOAK_OF_CHAOS;
                            iCasterLevel = 7;
                            i = 2;
                            ipItem = ItemPropertyDamageBonusVsAlign(IP_CONST_ALIGNMENTGROUP_LAWFUL,IP_CONST_DAMAGETYPE_DIVINE,IP_CONST_DAMAGEBONUS_2d6);
                            iAlign = IP_CONST_ALIGNMENTGROUP_CHAOTIC;
                            }
                        else if (sMaterial == "speedmat")
                            {
                            iSpell = SPELL_HASTE;
                            iCasterLevel = 7;
                            i = 4;
                            ipItem = ItemPropertyHaste();
                            }
                        else if (sMaterial == "brillmat")
                            {
                            iSpell = SPELL_CONTINUAL_FLAME;
                            iCasterLevel = 16;
                            i = 4;
                            iSpecial = IP_CONST_DAMAGETYPE_MAGICAL;
                            ipItem = ItemPropertyCastSpell(IP_CONST_CASTSPELL_UNIQUE_POWER_SELF_ONLY,IP_CONST_CASTSPELL_NUMUSES_UNLIMITED_USE);
                            }
                        }
                    else //Melee
                        {
                        if (sMaterial == "defmat")
                            {
                            iSpell = SPELL_SHIELD;
                            iSpell2 = SPELL_SHIELD_OF_FAITH;
                            iCasterLevel = 8;
                            i = 1;
                            ipItem = ItemPropertyACBonus(iEncTemp);
                            }
                        else if (sMaterial == "firemat2")
                            {
                            iSpell = SPELL_FIREBALL;
                            iSpell2 = SPELL_FLAME_WEAPON;
                            iSpell3 = SPELL_FLAME_STRIKE;
                            iCasterLevel = 10;
                            i = 1;
                            ipItem = ItemPropertyDamageBonus(IP_CONST_DAMAGETYPE_FIRE,IP_CONST_DAMAGEBONUS_1d6);
                            }
                        else if (sMaterial == "coldmat2")
                            {
                            iSpell = SPELL_ICE_STORM;
                            iCasterLevel = 8;
                            i = 1;
                            ipItem = ItemPropertyDamageBonus(IP_CONST_DAMAGETYPE_COLD,IP_CONST_DAMAGEBONUS_1d6);
                            }
                        else if (sMaterial == "elecmat2")
                            {
                            iSpell = SPELL_CALL_LIGHTNING;
                            iSpell2 = SPELL_LIGHTNING_BOLT;
                            iCasterLevel = 8;
                            i = 1;
                            ipItem = ItemPropertyDamageBonus(IP_CONST_DAMAGETYPE_ELECTRICAL,IP_CONST_DAMAGEBONUS_1d6);
                            }
                        else if (sMaterial == "sonicmat2")
                            {
                            iSpell = SPELL_SOUND_BURST;
                            iCasterLevel = 8;
                            i = 1;
                            ipItem = ItemPropertyDamageBonus(IP_CONST_DAMAGETYPE_SONIC,IP_CONST_DAMAGEBONUS_1d6);
                            }
                        else if (sMaterial == "keenmat")
                            {
                            iSpell = SPELL_KEEN_EDGE;
                            iCasterLevel = 10;
                            i = 1;
                            if (GetWeaponSlashing(oCraftable))
                                ipItem = ItemPropertyKeen();
                            else
                                {
                                FloatingTextStringOnCreature("Can only be placed on a slashing weapon.",oPC,FALSE);
                                return;
                                }
                            }
                        else if (sMaterial == "cleavingmat")
                            {
                            iSpell = SPELL_DIVINE_POWER;
                            iCasterLevel = 8;
                            i = 1;
                            ipItem = ItemPropertyBonusFeat(IP_CONST_FEAT_CLEAVE);
                            }
                        else if (sMaterial == "acidmat2")
                            {
                            iSpell = SPELL_MELFS_ACID_ARROW;
                            iSpell2 = SPELL_MESTILS_ACID_SHEATH;
                            iCasterLevel = 8;
                            i = 1;
                            ipItem = ItemPropertyDamageBonus(IP_CONST_DAMAGETYPE_ACID,IP_CONST_DAMAGEBONUS_1d6);
                            }
                        else if (sMaterial == "throwmat")
                            {
                            iSpell = SPELL_BULLS_STRENGTH;
                            iCasterLevel = 5;
                            i = 1;
                            ipItem = ItemPropertyCastSpell(IP_CONST_CASTSPELL_BULLS_STRENGTH_3,IP_CONST_CASTSPELL_NUMUSES_1_USE_PER_DAY);
                            }
                        else if (sMaterial == "banemat")
                            {
                            iSpell = SPELL_SUMMON_CREATURE_I;
                            iCasterLevel = 8;
                            i = 2;
                            iBane = GetBaneRace();
                            ipItem = ItemPropertyEnhancementBonusVsRace(iBane,iEncTemp+2);
                            }
                        else if (sMaterial == "disrmat")
                            {
                            iSpell = SPELL_HEAL;
                            iCasterLevel = 14;
                            i = 2;
                            if (GetWeaponBludgeoning(oCraftable))
                                ipItem = ItemPropertyOnHitProps(IP_CONST_ONHIT_SLAYRACE,IP_CONST_ONHIT_SAVEDC_14,IP_CONST_RACIALTYPE_UNDEAD);
                            else
                                {
                                FloatingTextStringOnCreature("Can only be placed on a bludgeoning weapon.",oPC,FALSE);
                                return;
                                }
                            }
                        else if (sMaterial == "firemat3")
                            {
                            iSpell = SPELL_FIREBALL;
                            iSpell2 = SPELL_FLAME_WEAPON;
                            iSpell3 = SPELL_FLAME_STRIKE;
                            iCasterLevel = 12;
                            i = 2;
                            ipItem = ItemPropertyDamageBonus(IP_CONST_DAMAGETYPE_FIRE,IP_CONST_DAMAGEBONUS_1d6);
                            iBurst = TRUE;
                            }
                        else if (sMaterial == "coldmat3")
                            {
                            iSpell = SPELL_ICE_STORM;
                            iCasterLevel = 10;
                            i = 2;
                            ipItem = ItemPropertyDamageBonus(IP_CONST_DAMAGETYPE_COLD,IP_CONST_DAMAGEBONUS_1d6);
                            iBurst = TRUE;
                            }
                        else if (sMaterial == "elecmat3")
                            {
                            iSpell = SPELL_CALL_LIGHTNING;
                            iSpell2 = SPELL_LIGHTNING_BOLT;
                            iCasterLevel = 10;
                            i = 2;
                            ipItem = ItemPropertyDamageBonus(IP_CONST_DAMAGETYPE_ELECTRICAL,IP_CONST_DAMAGEBONUS_1d6);
                            iBurst = TRUE;
                            }
                        else if (sMaterial == "sonicmat3")
                            {
                            iSpell = SPELL_SOUND_BURST;
                            iCasterLevel = 10;
                            i = 2;
                            ipItem = ItemPropertyDamageBonus(IP_CONST_DAMAGETYPE_SONIC,IP_CONST_DAMAGEBONUS_1d6);
                            iBurst = TRUE;
                            }
                        else if (sMaterial == "woundmat")
                            {
                            iSpell = SPELL_MORDENKAINENS_SWORD;
                            iCasterLevel = 10;
                            i = 2;
                            ipItem = ItemPropertyOnHitProps(IP_CONST_ONHIT_WOUNDING,IP_CONST_ONHIT_SAVEDC_20);
                            }
                        else if (sMaterial == "holymat")
                            {
                            if (GetAlignmentGoodEvil(oPC) != ALIGNMENT_GOOD)
                                {
                                FloatingTextStringOnCreature("Can only be placed by a person of good alignment.",oPC,FALSE);
                                return;
                                }
                            if (!GetHasFeat(FEAT_SMITE_EVIL,oPC))
                                {
                                FloatingTextStringOnCreature("Can only be placed by a person with the smite evil feat.",oPC,FALSE);
                                return;
                                }
                            iCasterLevel = 7;
                            i = 2;
                            ipItem = ItemPropertyDamageBonusVsAlign(IP_CONST_ALIGNMENTGROUP_EVIL,IP_CONST_DAMAGETYPE_DIVINE,IP_CONST_DAMAGEBONUS_2d6);
                            iAlign = IP_CONST_ALIGNMENTGROUP_GOOD;
                            }
                        else if (sMaterial == "unholymat")
                            {
                            if (GetAlignmentGoodEvil(oPC) != ALIGNMENT_EVIL)
                                {
                                FloatingTextStringOnCreature("Can only be placed by a person of evil alignment.",oPC,FALSE);
                                return;
                                }
                            iSpell = SPELL_UNHOLY_AURA;
                            iCasterLevel = 7;
                            i = 2;
                            ipItem = ItemPropertyDamageBonusVsAlign(IP_CONST_ALIGNMENTGROUP_GOOD,IP_CONST_DAMAGETYPE_DIVINE,IP_CONST_DAMAGEBONUS_2d6);
                            iAlign = IP_CONST_ALIGNMENTGROUP_EVIL;
                            }
                        else if (sMaterial == "lawfulmat")
                            {
                            if (GetAlignmentLawChaos(oPC) != ALIGNMENT_LAWFUL)
                                {
                                FloatingTextStringOnCreature("Can only be placed by a person of lawful alignment.",oPC,FALSE);
                                return;
                                }
                            iSpell = SPELL_SHIELD_OF_LAW;
                            iCasterLevel = 7;
                            i = 2;
                            ipItem = ItemPropertyDamageBonusVsAlign(IP_CONST_ALIGNMENTGROUP_CHAOTIC,IP_CONST_DAMAGETYPE_DIVINE,IP_CONST_DAMAGEBONUS_2d6);
                            iAlign = IP_CONST_ALIGNMENTGROUP_LAWFUL;
                            }
                        else if (sMaterial == "chaosmat")
                            {
                            if (GetAlignmentLawChaos(oPC) != ALIGNMENT_CHAOTIC)
                                {
                                FloatingTextStringOnCreature("Can only be placed by a person of chaotic alignment.",oPC,FALSE);
                                return;
                                }
                            iSpell = SPELL_CLOAK_OF_CHAOS;
                            iCasterLevel = 7;
                            i = 2;
                            ipItem = ItemPropertyDamageBonusVsAlign(IP_CONST_ALIGNMENTGROUP_LAWFUL,IP_CONST_DAMAGETYPE_DIVINE,IP_CONST_DAMAGEBONUS_2d6);
                            iAlign = IP_CONST_ALIGNMENTGROUP_CHAOTIC;
                            }
                        else if (sMaterial == "brillmat")
                            {
                            iSpell = SPELL_CONTINUAL_FLAME;
                            iCasterLevel = 16;
                            i = 4;
                            ipItem = ItemPropertyDamageBonus(IP_CONST_DAMAGETYPE_MAGICAL,IP_CONST_DAMAGEBONUS_1d6);
                            }
                        else if (sMaterial == "dancemat")
                            {
                            if (GetLevelByClass(CLASS_TYPE_BARD,oPC) < 15)
                                {
                                FloatingTextStringOnCreature("Can only be placed by a bard of at least 15th level.",oPC,FALSE);
                                return;
                                }
                            i = 4;
                            ipItem = ItemPropertyOnHitCastSpell(IP_CONST_ONHIT_CASTSPELL_SLOW,IP_CONST_SPELLLEVEL_5);
                            }
                        else if (sMaterial == "speedmat")
                            {
                            iSpell = SPELL_HASTE;
                            iCasterLevel = 7;
                            i = 4;
                            ipItem = ItemPropertyHaste();
                            }
                        else if (sMaterial == "vorpmat")
                            {
                            iSpell = SPELL_KEEN_EDGE;
                            iSpell2 = SPELL_FINGER_OF_DEATH;
                            iCasterLevel = 18;
                            i = 5;
                            if (GetWeaponSlashing(oCraftable))
                                ipItem = ItemPropertyOnHitProps(IP_CONST_ONHIT_VORPAL,IP_CONST_ONHIT_SAVEDC_20);
                            else
                                {
                                FloatingTextStringOnCreature("Can only be placed on a slashing weapon.",oPC,FALSE);
                                return;
                                }
                            }
                        }
                    }
                if (iEnc + i > 20)
                    return;
                iPrice = (GetTotalEnchantmentValue(oCraftable,i) - iValue)/2;
                iXPCost = GetItemXPCost(oCraftable,i);
                if (GetXP(oPC) - iXPCost < GetMinLevelXP(oPC))
                    {
                    FloatingTextStringOnCreature("You lack the experience to spend on crafting this item.",oPC,FALSE);
                    return;
                    }
                if (iGold >= iPrice)
                    {
                    if (GetHitDice(oPC) >= 2*(iEnc+i)
                     && GetSkillRank(iSkill,oPC) >= 2*(iEnc+i))
                        {
                        if (GetCasterLevel(oPC) < iCasterLevel)
                            {
                            if (GetCasterLevel(oPC) == 0)
                                FloatingTextStringOnCreature("Crafting requires that you cast a spell before begining, so that the forge can determine your caster level.",oPC,FALSE);
                            else
                                FloatingTextStringOnCreature("You require more levels before you can add this property.",oPC,FALSE);
                            return; //Didnt have proper spells ready.
                            }
                        if (iSpell != -1)
                            {
                            if(GetHasSpell(iSpell,oPC))
                                DecrementRemainingSpellUses(oPC,iSpell);
                            else if(GetHasSpell(iSpell2,oPC) && iSpell2 != -1)
                                DecrementRemainingSpellUses(oPC,iSpell2);
                            else if(GetHasSpell(iSpell3,oPC) && iSpell3 != -1)
                                DecrementRemainingSpellUses(oPC,iSpell3);
                            else
                                {
                                FloatingTextStringOnCreature("Improper spells ready.",oPC,FALSE);
                                return; //Didnt have proper spells ready.
                                }
                            }
                        if (iHFort)
                            {
                            IPSafeAddItemProperty(oCraftable,ItemPropertyImmunityMisc(IP_CONST_IMMUNITYMISC_BACKSTAB));
                            IPSafeAddItemProperty(oCraftable,ItemPropertyImmunityMisc(IP_CONST_IMMUNITYMISC_CRITICAL_HITS));
                            IPSafeAddItemProperty(oCraftable,ItemPropertyImmunityMisc(IP_CONST_IMMUNITYMISC_KNOCKDOWN));
                            }
                        else
                            IPSafeAddItemProperty(oCraftable,ipItem);
                        if (iBurst)
                            IPSafeAddItemProperty(oCraftable,ItemPropertyMassiveCritical(IP_CONST_DAMAGEBONUS_1d10));
                        if (iAlign != -1 && !iLauncher)
                            IPSafeAddItemProperty(oCraftable,ItemPropertyLimitUseByAlign(iAlign));
                        else if (iAlign != -1 && iLauncher)
                            {
                            SetLocalInt(oCraftable,"SpecialAmmo",2);
                            SetLocalInt(oCraftable,"DamageType",IP_CONST_DAMAGETYPE_DIVINE);
                            SetLocalInt(oCraftable,"AlignmentTarget",iAlign);
                            }
                        if (iBane != -1 && !iLauncher)
                            IPSafeAddItemProperty(oCraftable,ItemPropertyDamageBonusVsRace(iBane,IP_CONST_DAMAGETYPE_MAGICAL,IP_CONST_DAMAGEBONUS_2d6));
                        else if (iBane != 1 && iLauncher)
                            {
                            SetLocalInt(oCraftable,"Bane",iBane);
                            SetLocalInt(oCraftable,"SpecialAmmo",3);
                            SetLocalInt(oCraftable,"DamageType",IP_CONST_DAMAGETYPE_MAGICAL);
                            }
                        if (iLauncher != 0 && iSpecial != -1)
                            {
                            SetLocalInt(oCraftable,"SpecialAmmo",TRUE);
                            SetLocalInt(oCraftable,"DamageType",iSpecial);
                            }
                        SetLocalInt(oCraftable,"Enc",iEnc + i);
                        DestroyObject(oMaterial);
                        iPassed = TRUE;
                        }
                    }
                }
            else // Standard +1 to 20 Enchantment
                {
                iPrice = (GetTotalEnchantmentValue(oCraftable,1) - iValue)/2;
                i = iEncTemp + 1;
                iXPCost = GetItemXPCost(oCraftable,i);
                if (GetXP(oPC) - iXPCost < GetMinLevelXP(oPC))
                    {
                    FloatingTextStringOnCreature("You lack the experience to spend on crafting this item.",oPC,FALSE);
                    return;
                    }
                if (iGold >= iPrice)
                    {
                    if (iLauncher)
                        ipItem = ItemPropertyAttackBonus(i);
                    else if (GetIsArmor(oCraftable))
                        ipItem = ItemPropertyACBonus(i);
                    else
                        ipItem = ItemPropertyEnhancementBonus(i);
                    if (GetHitDice(oPC) >= 2*i
                     && GetSkillRank(iSkill,oPC) >= 2*i)
                        {
                        IPSafeAddItemProperty(oCraftable,ipItem);
                        SetLocalInt(oCraftable,"Enc",iEnc += 1);
                        iPassed = TRUE;
                        }
                    }
                }
            }
        else // Master working
            {
            if (GetIsObjectValid(oMaterial))
                {
                if ((iSkill == SKILL_CRAFT_WEAPON
                 && sMaterial == "mwweaponmat")
                || (iSkill == SKILL_CRAFT_ARMOR
                 && sMaterial == "wmarmormat"))
                    {
                    if (GetIsSkillSuccessful(oPC,iSkill,iDC))
                        {
                        SetLocalInt(oCraftable,"MW",TRUE);
                        ApplyEffectAtLocation(DURATION_TYPE_TEMPORARY,EffectVisualEffect(VFX_IMP_KNOCK),GetLocation(OBJECT_SELF));
                        }
                    DestroyObject(oMaterial);
                    }
                }
            }
        }
    //---------------------------- END RECIPES------------------------------
    if(iPassed)
        {
        GiveGoldToCreature(oPC,iGold - iPrice);
        SetXP(oPC,iXP - iXPCost);
        DestroyGold();
        ApplyEffectAtLocation(DURATION_TYPE_TEMPORARY,EffectVisualEffect(VFX_IMP_KNOCK),GetLocation(OBJECT_SELF));
        }
    SoundObjectPlay(oSound);
    }
