//////////////////////////////////////////////////////////
/*
   Item Appearance Modification Conversation
   Finish Conversation Script
*/
// created/updated 2003-06-24 Georg Zoeller, Bioware Corp
//////////////////////////////////////////////////////////
#include "prc_x2_craft"
#include "jw_inc_craft"

void main()
{
    object oPC = GetPCSpeaker();
    if (CIGetCurrentModMode(GetPCSpeaker()) != X2_CI_MODMODE_INVALID )
    {
        object oBackup = CIGetCurrentModBackup(oPC);

        int nCost = GetLocalInt(oPC,"X2_TAILOR_CURRENT_COST");
        int nDC =  GetLocalInt(oPC,"X2_TAILOR_CURRENT_DC");



        object oNew = CIGetCurrentModItem(oPC);
        // remove the death int
        DeleteLocalInt(oNew,"jw_craft_copy");
        AssignCommand(oPC,ClearAllActions(TRUE));
        if (CIGetCurrentModMode(oPC) == X2_CI_MODMODE_ARMOR)
        {
             AssignCommand(oPC, ActionEquipItem(oNew,INVENTORY_SLOT_CHEST));
        }
        else if (CIGetCurrentModMode(oPC) == X2_CI_MODMODE_WEAPON)
        {
               AssignCommand(oPC, ActionEquipItem(oNew,INVENTORY_SLOT_RIGHTHAND));
        }
        else if (CIGetCurrentModMode(oPC) == X2_CI_MODMODE_HELMET)
        {
               AssignCommand(oPC, ActionEquipItem(oNew,INVENTORY_SLOT_HEAD));
        }
        else if (CIGetCurrentModMode(oPC) == X2_CI_MODMODE_SHIELD)
        {
               AssignCommand(oPC, ActionEquipItem(oNew,INVENTORY_SLOT_LEFTHAND));
        }
        ///----------------------------------------------------------------------
        // This is to work around a problem with temporary item properties
        // sometimes staying around when they are on a cloned item.
        //----------------------------------------------------------------------
        IPRemoveAllItemProperties(oNew,DURATION_TYPE_TEMPORARY);

        DeleteLocalInt(oPC,"X2_TAILOR_CURRENT_COST");
        DeleteLocalInt(oPC,"X2_TAILOR_CURRENT_DC");
        CISetCurrentModMode(oPC,X2_CI_MODMODE_INVALID );

        // remove backup
        DestroyObject(oBackup);
    }
    else
    {
       ClearAllActions();
    }

    // Remove custscene immobilize from player
    effect eEff = GetFirstEffect(oPC);
    while (GetIsEffectValid(eEff))
    {
         if (GetEffectType(eEff) == EFFECT_TYPE_CUTSCENEIMMOBILIZE
             && GetEffectCreator(eEff) == oPC
             && GetEffectSubType(eEff) == SUBTYPE_EXTRAORDINARY )
         {
            RemoveEffect(oPC,eEff);
         }
         eEff = GetNextEffect(oPC);
     }

    RestoreCameraFacing() ;

 ExportSingleCharacter(oPC);
}