//::///////////////////////////////////////////////
//:: [Dominate Animal]  (Harper Class Ability "Llurue's Voice")
//:: [NW_S2_DomAn.nss]
//:: Copyright (c) 2000 Bioware Corp.
//:://////////////////////////////////////////////
//:: Will save or the target is dominated for 1 round
//:: per caster level.
//:://////////////////////////////////////////////
//:: Created By: Preston Watamaniuk
//:: Created On: Jan 30, 2001
//:://////////////////////////////////////////////
//:: VFX Pass By: Preston W, On: June 20, 2001
//:: Update Pass By: Preston W, On: July 30, 2001


// JLR-OEI 04/02/06: For GDD Update


#include "NW_I0_SPELLS"    
#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_DOM_ANIMAL );

    int nMetaMagic = JXGetMetaMagicFeat();
    int nCasterLevel = GetTotalLevels(OBJECT_SELF, 1); //JXGetCasterLevel(OBJECT_SELF);
    int nDuration = 3 + nCasterLevel;
    int nRacial = GetRacialType(oTarget);
    //Fire cast spell at event for the specified target
    SignalEvent(oTarget, EventSpellCastAt(OBJECT_SELF, SPELL_DOMINATE_ANIMAL, FALSE));
    //Make sure the target is an animal
	if (spellsIsTarget(oTarget, SPELL_TARGET_STANDARDHOSTILE, OBJECT_SELF))
	{
        if  ((nRacial == RACIAL_TYPE_ANIMAL || nRacial == RACIAL_TYPE_BEAST))
        {
           //Make SR check
           if (!MyResistSpell(OBJECT_SELF, oTarget))
    	   {
                //Will Save for spell negation
                if (!/*Will Save*/ MySavingThrow(SAVING_THROW_WILL, oTarget, JXGetSpellSaveDC(), SAVING_THROW_TYPE_MIND_SPELLS))
                {
                    //Check for Metamagic extension
                    if (nMetaMagic & METAMAGIC_EXTEND)
                    {
                        nDuration = nDuration * 2;
                    }
                    //Apply linked effect and VFX impact
                    JXApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, oTarget);
					JXApplyDominatedEffectToObject(oTarget, RoundsToSeconds(nDuration));
                }
            }
        }
    }

	JXPostSpellCastCode();
}
