//::///////////////////////////////////////////////
//:: Ghostly Visage
//:: NW_S0_MirrImage.nss
//:: Copyright (c) 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
    Caster gains 5/+1 Damage reduction and immunity
    to 1st level spells.
*/
//:://////////////////////////////////////////////
//:: Created By: Preston Watamaniuk
//:: Created On: Jan 7, 2001
//:://////////////////////////////////////////////
//:: AFW-OEI 08/03/2007: Account for Assassins.

#include "jx_inc_magic"
#include "x2_inc_spellhook" 

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

void mainSpell()
{

/* 
  Spellcast Hook Code 
  Added 2003-06-23 by GeorgZ
  If you want to make changes to all spells,
  check x2_inc_spellhook.nss to find out more
  
*/

    if (!X2PreSpellCastCode())
    {
	// If code within the PreSpellCastHook (i.e. UMD) reports FALSE, do not run this spell
        JXPostSpellCastCode();
		return;
    }

// End of Spell Cast Hook


    //Declare major variables
    object oTarget = JXGetSpellTargetObject();
	effect eVis = EffectVisualEffect( VFX_DUR_SPELL_GHOSTLY_VISAGE );
    //effect eDam = EffectDamageReduction(5, DAMAGE_POWER_PLUS_ONE);	// 3.0 DR rules
    effect eDam = EffectDamageReduction( 5, DAMAGE_POWER_PLUS_ONE, 0, DR_TYPE_MAGICBONUS );		// 3.5 DR approximation
    effect eSpell = EffectSpellLevelAbsorption(1);
    effect eConceal = EffectConcealment(10);
    //effect eDur = EffectVisualEffect( VFX_DUR_SPELL_GHOSTLY_VISAGE );
    effect eLink = EffectLinkEffects(eDam, eVis);
    eLink = EffectLinkEffects(eLink, eSpell);
    eLink = EffectLinkEffects(eLink, eConceal);
    //eLink = EffectLinkEffects(eLink, eDur);
    int nMetaMagic = JXGetMetaMagicFeat();
    int nDuration = JXGetCasterLevel(OBJECT_SELF);

	if (JXGetSpellId() == SPELLABILITY_AS_GHOSTLY_VISAGE)
	{	// Duration is equal to Assassin level for Assassins.
		nDuration = GetLevelByClass(CLASS_TYPE_ASSASSIN);
	}

    //Fire cast spell at event for the specified target
    SignalEvent(oTarget, EventSpellCastAt(OBJECT_SELF, SPELL_GHOSTLY_VISAGE, FALSE));

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

	JXPostSpellCastCode();
}
