/*
A combination of the scripts used for the powder that beats the crap out of J'nah
and the invulnerability on Desther.
*/


#include "nw_i0_generic"
void main()
{
    object oPC = GetItemActivator();
    object oRing = GetItemActivated();
    object oKaleth = GetItemActivatedTarget();

    if (GetTag(oKaleth) == "Kaleth_End" && GetTag(GetArea(GetItemActivator())) == "TempleofSharKalethsChambers" && GetLocalInt(oPC, "UsedRelicOnce") != TRUE)
    {
        DelayCommand(4.0, SetLocalInt(oPC, "UsedRelicOnce", TRUE));
        AssignCommand(oKaleth, ClearAllActions(TRUE));
        AssignCommand(oKaleth, ActionPlayAnimation(ANIMATION_LOOPING_SPASM, 2.0, 2.0));
        DelayCommand(1.5, AssignCommand(oKaleth, ActionSpeakString("NO! The link... is... broken!")));
                    // Define the effects.
        effect eFirst = EffectCutsceneParalyze();
        effect eVis = EffectVisualEffect(VFX_IMP_CHARM);
        effect eVis2 = EffectVisualEffect(VFX_IMP_BLIND_DEAF_M);
        effect eVis3 = EffectVisualEffect(VFX_IMP_DEATH_WARD);
        effect eVis4 = EffectVisualEffect(VFX_FNF_DISPEL);
                    // Apply the effects.
        ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eFirst, oKaleth, 4.0);
        ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, oKaleth);
        DelayCommand(0.5, ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis2, oKaleth));
        DelayCommand(1.0, ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis2, oKaleth));
        DelayCommand(1.0, ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, oKaleth));
        DelayCommand(0.5, ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis3, oKaleth));
        DelayCommand(2.0, ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, oKaleth));
        DelayCommand(2.5, ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis4, oKaleth));
        SetImmortal(oKaleth, FALSE);
        /*
                    // Remove the Invulnerability from Kaleth.
        effect eInvuln01 = GetFirstEffect(oKaleth);
            while (GetIsEffectValid(eInvuln01))
            {
            if (GetEffectType(eInvuln01) == EFFECT_TYPE_SPELL_RESISTANCE_INCREASE)
            RemoveEffect(oKaleth, eInvuln01);
            eInvuln01 = GetNextEffect(oKaleth);
            }
        effect eInvuln02 = GetFirstEffect(oKaleth);
            while (GetIsEffectValid(eInvuln02))
            {
            if (GetEffectType(eInvuln02) == EFFECT_TYPE_DAMAGE_IMMUNITY_INCREASE)
            RemoveEffect(oKaleth, eInvuln02);
            eInvuln02 = GetNextEffect(oKaleth);
            }
        */
                // Piss her off.
        SetIsTemporaryEnemy(oPC, oKaleth);
        AssignCommand(oKaleth, DetermineCombatRound(oPC));
    }

    else {
                // Don't use it at the wrong time, dummy!
        FloatingTextStringOnCreature("This is a highly potent magical device. You don't just go about using on a whim!", oPC);
        }

}
