

/******************************************************************************
*   NOTE: This file will expect prior actions to have altered
*   BZMSCAK.D and yielded internal WeiDU strings:
*       - Potions/BZMSCAK.D
******************************************************************************/

//Emit the final result prior to compilation
COPY -
    ~./%MOD_FOLDER%/comp/crafting-potion/DLG/BZMSCAK.d~
    ~Generated/BZMSCAK.d~
        //Patches
        APPEND_FILE TEXT ~./%MOD_FOLDER%/comp/crafting-potion/%bz_edition_code%/DLG/BZMSCAK.D~
        APPEND_FILE TEXT ~Potions/BZMSCAK.D~

//DEBUG so I can read it
COPY +
    ~Generated/BZMSCAK.d~
    ~./%MOD_FOLDER%/comp/crafting-potion/DLG/BZMSCAK.DEBUG.d~

//compile the new dialog (with huge mutated edits)
COMPILE ~Generated/BZMSCAK.d~




/***************************
*   Make the brewing kit   *
***************************/
//Copy BAMs for item
COPY ~./%MOD_FOLDER%/comp/crafting-potion/BAM/BZMIAKD.BAM~ ~override~    //alchemy kit description BAM
COPY ~./%MOD_FOLDER%/comp/crafting-potion/BAM/BZMIAKI.BAM~ ~override~    //alchemy kit inventory BAM



//Make an item for the player to interact with
ACTION_IF (~%bz_game_code%~ STRING_EQUAL ~pstee~)
THEN
BEGIN
    COPY_EXISTING ~DBOX.ITM~ ~override/BZMSCAK.ITM~   //scribe kit
        //Patches
            SAY NAME1 @20050 //Scribe's Tool Kit
            SAY NAME2 @20050 //Scribe's Tool Kit
            SAY UNIDENTIFIED_DESC @20002
            SAY IDENTIFIED_DESC @20051
            WRITE_ASCII 0x3A "BZMIAKI" (8)                  // Icon
            WRITE_LONG 0x34 2000                            // Price
            WRITE_SHORT 0x38 1                              // Stack Size
            WRITE_LONG 0x42 10                              // Lore to Identify
            WRITE_LONG 0x4C 10                              // Weight
            READ_LONG 0x18 ~bzmsckar_flags~
            WRITE_LONG 0x18 (%bzmsckar_flags% BOR BIT11)    //set conversible
            WRITE_ASCII 0x58 "Z_CLOTH1" (8)                 // Pick up Sound
            WRITE_ASCII 0x10 "Z_CLOTH2" (8)                 // Drop Sound
            WRITE_LONG 0x1C 0                               // Category: Miscellaneous
            WRITE_LONG 0x1E
                BIT31 BOR BIT29 BOR BIT28 BOR BIT26 BOR BIT25 BOR
                BIT23 BOR BIT22 BOR BIT21 BOR BIT17 BOR BIT11 // unusability flags: Not non-mages
END
ELSE
BEGIN
    COPY_EXISTING ~MISC01.ITM~ ~override/BZMSCAK.ITM~   //scribe kit
        //Patches
            SAY NAME1 @20050 //Scribe's Tool Kit
            SAY NAME2 @20050 //Scribe's Tool Kit
            SAY UNIDENTIFIED_DESC @20002
            SAY IDENTIFIED_DESC @20051
            WRITE_ASCII 0x3A "BZMIAKI" (8)                  // Icon
            WRITE_LONG 0x34 2000                            // Price
            WRITE_SHORT 0x38 1                              // Stack Size
            WRITE_SHORT 0x42 10                             // Lore to Identify
            WRITE_LONG 0x4C 20                              // Weight
            WRITE_ASCII 0x58 "BZMIAKD" (8)                  // Description Image
            READ_LONG 0x18 ~bzmsckar_flags~
            WRITE_LONG 0x18 (%bzmsckar_flags% BOR BIT11)    //set conversible
END



//Register the item in ITEMDIAL.2DA along with the strref to talk to it.
OUTER_SET bz_alchemy_kit_interact_strref = RESOLVE_STR_REF(@20052)

COPY_EXISTING ~ITEMDIAL.2DA~ ~override~
    //PATCHES
        COUNT_2DA_ROWS 3 ~bz_itemdial_ct~
        INSERT_2DA_ROW %bz_itemdial_ct% 3 ~BZMSCAK %bz_alchemy_kit_interact_strref% BZMSCAK~



//Add the kit to stores
INCLUDE ~./%MOD_FOLDER%/comp/shared/fn-add_kit_to_stores.tph~

LAUNCH_ACTION_FUNCTION ~bz_add_kit_to_stores~
STR_VAR
    ~Item_RESREF~ = ~BZMSCAK~
END
