//::///////////////////////////////////////////////
//:: Wildmage Post Spellhook script
//::///////////////////////////////////////////////
/*

This scrip controlls all events that fire after a spell script is finished.

*/
//::///////////////////////////////////////////////
//:: Created By: 2DruNk2Frag & Shazbotian
//:: Created On: 04-03-2008
//:: 04-18-08: 2d2f - Added code to remove permenent supernatural effects with dispel magic
//:: 05-06-08: 2d2f - Added code to remove zombibied surge 
//::///////////////////////////////////////////////

//#include "nwn2_inc_spells"
//#include "x2_inc_switches"
//#include "2d2f_includes"
#include "2d2f_inc_magic_wild"
//#include "jx_inc_magic"
//#include "jx_inc_magic_info"
//#include "x0_i0_spells"
//#include "x2_inc_itemprop"
//#include "NW_I0_GENERIC"


void main()
{
	object oPC = GetFirstPC();
	object oCaster = OBJECT_SELF;
	object oTarget = JXGetSpellTargetObject();
	//int nCasterLvl = JXGetCasterLevel(OBJECT_SELF);
	int nSpellId = GetSpellId();
	
	//2d2f: every time dispel magic is cast it will check for supernatural surge effects
	// and remove them
	if(nSpellId == 94 || 
	nSpellId == 41 || 
	nSpellId == 1033 || 
	nSpellId == 67 || 
	nSpellId == 1034 || 
	nSpellId == 122) 
	{
		int nColorChangeId = GetLocalInt(oTarget,"nColorChangeId");
		int nRandomLimbId = GetLocalInt(oTarget,"nRandomLimbId");
		int nRaceChanged = GetLocalInt(oTarget,"nRaceChanged");
		
		if(nColorChangeId > 0)
		{
			RemoveSupernaturalEffectWithSpellId(oTarget,nColorChangeId);
			DeleteLocalInt(oTarget,"nColorChangeId");
			SpeakString("Their skin regains its natural pigment.");
		}
		if(nRandomLimbId > 0)
		{
			RemoveSupernaturalEffectWithSpellId(oTarget,nRandomLimbId);
			DeleteLocalInt(oTarget,"nRandomLimbId");
			SpeakString("The anomlous bodily feature shrivels away.");
		}
        if(nRaceChanged == 1)
        {
            RemoveRacialAbilities(oTarget,GetLocalInt(oTarget,"nFakeRace"));
            AddRacialAbilities(oTarget,GetSubRace(oTarget));
            RemoveSupernaturalEffectWithSpellId(oTarget,SURGE_TEMP_SPELLID_RACIAL_STATS);
            RemoveSupernaturalEffectWithSpellId(oTarget,SURGE_TEMP_SPELLID_ORIGINAL_RACIAL_STATS);
                       
            int nSexChanged = GetLocalInt(oTarget,"nSexChanged");
            
            if(nSexChanged == 0)
            {                
                SetCreatureAppearanceType(oTarget,GetLocalInt(oTarget,"nOriginalAppearance"));
            }
            else
            {
                int nSex = SexChange(oTarget,TRUE);                
            }   
                     
            DeleteLocalInt(oTarget,"nOriginalRaceStatReduction");
            DeleteLocalInt(oTarget,"nRaceChanged");
            DeleteLocalInt(oTarget,"nFakeRace");
            SpeakString("Your body returns to its birth race.");
        }
	}
	
	//code to remove undead effect surge with raise dead or resurection spell
	if(nSpellId == 142 || nSpellId == 153)
	{
		int nZombifiedId = GetLocalInt(oTarget,"nZombified");
		if(nZombifiedId > 0)
		{
			object oUndeadProps = GetItemInSlot(INVENTORY_SLOT_CARMOUR , oTarget);
			AssignCommand(oPC, ActionUnequipItem(oUndeadProps));
			DestroyObject(oUndeadProps);
     		RemoveSupernaturalEffectWithSpellId(oTarget,nZombifiedId);
			DeleteLocalInt(oTarget,"nZombified");
			SpeakString("The Undeath is purged from your body.");
		}
	
	}
	


}