//::///////////////////////////////////////////////
//:: Create Greater Undead
//:: NW_S0_CrGrUnd.nss
//:: Copyright (c) 2005 Obsidian Entertainment
//:://////////////////////////////////////////////
/*
    Summons an undead type pegged to the character's
    level.
*/
//:://////////////////////////////////////////////
//:: Created By: Preston Watamaniuk
//:: Created On: April 12, 2001
//:://////////////////////////////////////////////

//:://////////////////////////////////////////////
//:: Update By: Brock H. - OEI
//:: Update On: 10/07/05
//:: Changed summoned creature resrefs
//:://////////////////////////////////////////////
//:: AFW-OEI 06/02/2006:
//::	Updated creature blueprints
//::	Changed duration from 24 hours to CL hours


#include "jx_inc_magic"
#include "x2_inc_spellhook" 

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

void mainSpell()
{

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


    //Declare major variables
    int nMetaMagic = JXGetMetaMagicFeat();
    int nCasterLevel = JXGetCasterLevel(OBJECT_SELF);
    int nDuration = nCasterLevel;
    //nDuration = 24;
    effect eSummon;
    
    //Make metamagic extend check
    if (nMetaMagic & METAMAGIC_EXTEND)
    {
        nDuration = nDuration *2;	//Duration is +100%
    }
    //Determine undead to summon based on level
    if (nCasterLevel <= 15)
    {
        eSummon = EffectSummonCreature("c_shadow",VFX_HIT_SPELL_SUMMON_CREATURE);
    }
    else if ((nCasterLevel >= 16) && (nCasterLevel <= 17))
    {
        eSummon = EffectSummonCreature("c_wraith",VFX_HIT_SPELL_SUMMON_CREATURE);
    }
    else if ((nCasterLevel >= 18) && (nCasterLevel <= 19))
    {
        eSummon = EffectSummonCreature("c_vampirem",VFX_HIT_SPELL_SUMMON_CREATURE);
    }
    else
    {
        eSummon = EffectSummonCreature("c_vampireelite",VFX_HIT_SPELL_SUMMON_CREATURE);
    }
    
	//Apply summon effect and VFX impact.
    JXApplyEffectAtLocation(DURATION_TYPE_TEMPORARY, eSummon, JXGetSpellTargetLocation(), HoursToSeconds(nDuration));
    

	JXPostSpellCastCode();
}
