#include "x2_inc_itemprop"

//This is actually the main function.
void script(object oItem, object oPC)
{
     itemproperty ipAdd;
     int nBonus = 1;
     if (GetLocalString(oPC, "LastProperty") == "AC") ipAdd = ItemPropertyACBonus(nBonus);
     if (GetLocalString(oPC, "LastProperty") == "Regeneration") ipAdd = ItemPropertyRegeneration(nBonus);
     if (GetLocalString(oPC, "LastProperty") == "Throws") ipAdd = ItemPropertyBonusSavingThrowVsX(IP_CONST_SAVEVS_UNIVERSAL, nBonus);
     if (GetLocalString(oPC, "LastProperty") == "StrengthAbility") ipAdd = ItemPropertyAbilityBonus(IP_CONST_ABILITY_STR, nBonus);
     if (GetLocalString(oPC, "LastProperty") == "DexterityAbility") ipAdd = ItemPropertyAbilityBonus(IP_CONST_ABILITY_DEX, nBonus);
     if (GetLocalString(oPC, "LastProperty") == "ConstitutionAbility") ipAdd = ItemPropertyAbilityBonus(IP_CONST_ABILITY_CON, nBonus);
     if (GetLocalString(oPC, "LastProperty") == "IntelligenceAbility") ipAdd = ItemPropertyAbilityBonus(IP_CONST_ABILITY_INT, nBonus);
     if (GetLocalString(oPC, "LastProperty") == "WisdomAbility") ipAdd = ItemPropertyAbilityBonus(IP_CONST_ABILITY_WIS, nBonus);
     if (GetLocalString(oPC, "LastProperty") == "CharismaAbility") ipAdd = ItemPropertyAbilityBonus(IP_CONST_ABILITY_CHA, nBonus);
     if (GetLocalString(oPC, "LastProperty") == "Enhancement") ipAdd = ItemPropertyEnhancementBonus(nBonus);
     IPSafeAddItemProperty(oItem, ipAdd);
}

void main()
{
     object oPC = GetPCSpeaker();
     int nSlot = 0;
     object oItem;

     //Check if the item being crafted is equipped
     while (nSlot < 18)
     {
     oItem = GetItemInSlot(nSlot, oPC);
     if (GetLocalInt(oItem, "Prototype") == TRUE) {script(oItem, oPC); return; }
     nSlot++;
     }
     //If the item is not equipped, search for it in the inventory
     oItem = GetFirstItemInInventory(oPC);
     while (GetIsObjectValid(oItem))
     {
     if (GetLocalInt(oItem, "Prototype") == TRUE) {script(oItem, oPC); return; }
     oItem = GetNextItemInInventory(oPC);
     }
}