//::///////////////////////////////////////////////
//:: Divine Protection
//:: NW_S2_DivProt.nss
//:: Copyright (c) 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
    Makes the target creature invisible to hostile
    creatures unless they make a Will Save to ignore
    the Sanctuary Effect
*/
//:://////////////////////////////////////////////
//:: Created By: Preston Watamaniuk
//:: Created On: Jan 8, 2002
//:://////////////////////////////////////////////

#include "jx_inc_magic"
#include "x2_inc_spellhook"

void mainSpell();
void main()
{
	AssignCommand(JXGetCaster(), mainSpell());
}

void mainSpell()
{
	if (!X2PreSpellCastCode()) { JXPostSpellCastCode(); return; }


	//Declare major variables
    object oTarget = JXGetSpellTargetObject();
	effect eVis = EffectVisualEffect(VFX_DUR_SPELL_SANCTUARY);
    //effect eDur = EffectVisualEffect(VFX_DUR_CESSATE_POSITIVE);
    int nDC = 10 + GetAbilityModifier(ABILITY_CHARISMA) + GetLevelByClass(CLASS_TYPE_CLERIC);
    effect eSanc = EffectSanctuary(nDC);
    
    effect eLink = EffectLinkEffects(eVis, eSanc);
    //eLink = EffectLinkEffects(eLink, eDur);
    //Fire cast spell at event for the specified target
    SignalEvent(OBJECT_SELF, EventSpellCastAt(OBJECT_SELF, SPELLABILITY_DIVINE_PROTECTION, FALSE));

    int nDuration = JXGetCasterLevel(OBJECT_SELF);
    //Enter Metamagic conditions
    int nMetaMagic = JXGetMetaMagicFeat();
    if (nMetaMagic & METAMAGIC_EXTEND)
    {
    	nDuration = nDuration *2; //Duration is +100%
    }
    //Apply the VFX impact and effects
    JXApplyEffectToObject(DURATION_TYPE_TEMPORARY, eLink, oTarget, RoundsToSeconds(nDuration));

	JXPostSpellCastCode();
}
