////////////////////////////////////////////////////////////
/*
   Item Appearance Modification Conversation
   Changes the appearance of the currently active armorpart
   on the tailor to the next available appearance
*/
// created/updated 2003-06-24 Georg Zoeller, Bioware Corp
///////////////////////////////////////////////////////////
#include "prc_x2_craft"
#include "jw_inc_craft"

void main()
{
    int nPart =  GetLocalInt(OBJECT_SELF,"X2_TAILOR_CURRENT_PART");
    object oPC = GetPCSpeaker();
    object oItem = CIGetCurrentModItem(oPC);

    int nCurrentAppearance;
    if (CIGetCurrentModMode(oPC) ==  X2_CI_MODMODE_ARMOR)
    {
        nCurrentAppearance = GetItemAppearance(oItem,ITEM_APPR_TYPE_ARMOR_MODEL,nPart);
    }

    if(GetIsObjectValid(oItem) == TRUE)
    {
        // Store the cost for modifying this item here
        int nCost;
        int nDC;
        object oNew;
        AssignCommand(oPC,ClearAllActions(TRUE));
        if (CIGetCurrentModMode(oPC) ==  X2_CI_MODMODE_ARMOR)
        {
            oNew = IPGetModifiedArmor(oItem, nPart, X2_IP_ARMORTYPE_PREV, TRUE);
            CISetCurrentModItem(oPC,oNew);
            AssignCommand(oPC, ActionEquipItem(oNew, INVENTORY_SLOT_CHEST));
            nCost = CIGetArmorModificationCost(CIGetCurrentModBackup(oPC),oNew);
            nDC =CIGetArmorModificationDC(CIGetCurrentModBackup(oPC),oNew);
        } else if (CIGetCurrentModMode(oPC) ==  X2_CI_MODMODE_WEAPON)
        {
            oNew = JWGetColouredWeapon (oItem, nPart, X2_IP_WEAPONTYPE_NEXT, TRUE);
            CISetCurrentModItem(oPC,oNew);
            AssignCommand(oPC, ActionEquipItem(oNew, INVENTORY_SLOT_RIGHTHAND));
            nCost = CIGetWeaponModificationCost(CIGetCurrentModBackup(oPC),oNew); //CIGetArmorModificationCost(CIGetCurrentModBackup(oPC),oNew);
            nDC = JWGetWeaponModificationDC(CIGetCurrentModBackup(oPC),oNew);
            // Palmer - make it 30 for wizards staffs
            if (GetBaseItemType(oNew)==BASE_ITEM_MAGICSTAFF)
            {
             nDC = nDC+10;
            }
        }
        else if (CIGetCurrentModMode(oPC) ==  X2_CI_MODMODE_HELMET)
        {             //
            oNew = JWGetModifiedHelmet  (oItem, X2_IP_ARMORTYPE_PREV, TRUE);
            CISetCurrentModItem(oPC,oNew);
            AssignCommand(oPC, ActionEquipItem(oNew, INVENTORY_SLOT_HEAD));

            nDC=JWGetHelmetModificationDC(oNew); // 10 for normal helmets 20 for nice ones
            nCost=JWGetHelmetModificationCost(oNew); // 100 for normal helmets 500 for nice ines

        }
        else if (CIGetCurrentModMode(oPC) ==  X2_CI_MODMODE_SHIELD)
        {             //
            oNew = JWGetColouredShield (oItem, X2_IP_ARMORTYPE_PREV, TRUE);
            CISetCurrentModItem(oPC,oNew);
            AssignCommand(oPC, ActionEquipItem(oNew, INVENTORY_SLOT_LEFTHAND));

           nDC=JWGetShieldModificationDC(oNew); // from 5 to 25
            nCost=JWGetShieldModificationCost(oNew); // from 50 to 800
        }

        if (GetIsDM(GetPCSpeaker())||GetIsDMPossessed(GetPCSpeaker()))
        {
         nCost=0;
         nDC=0;
        }
        CIUpdateModItemCostDC(oPC, nDC, nCost);
    }
}