//::///////////////////////////////////////////////
//:: Magic Jar
//:://////////////////////////////////////////////
#include "x2_inc_spellhook"
void ApplyThirdEffect(object oTarget)
{
effect eDeath = EffectDeath(TRUE, TRUE, TRUE, TRUE ) ;
effect eDisappear = EffectDisappear();
if (GetCurrentHitPoints (oTarget) == 1) // died
{
DelayCommand(0.0, SetImmortal(oTarget, FALSE));
DelayCommand(0.1, ApplyEffectToObject(DURATION_TYPE_INSTANT, eDisappear, oTarget));
DelayCommand(1.0, ApplyEffectToObject( DURATION_TYPE_INSTANT, eDeath, OBJECT_SELF));
return;
}
else // unsummoned
{
DelayCommand(1.0, ApplyThirdEffect(oTarget));
}
}
void ApplySecondEffect()
{
effect eDisappear = EffectDisappear();
location lTarget = GetSpellTargetLocation();
object oTarget = GetFirstObjectInShape(SHAPE_SPHERE, RADIUS_SIZE_MEDIUM, lTarget, TRUE, OBJECT_TYPE_CREATURE);
effect eHeal = EffectHealOnZeroHP(oTarget, 50);
// FloatingTextStrRefOnCreature(100775,OBJECT_SELF,FALSE);
//Cycle through the targets within the spell shape until an invalid object is captured.
while (GetIsObjectValid(oTarget))
{
if (GetTag(oTarget)== "AA_MagicJar")
{
DelayCommand(0.3, ApplyEffectToObject(DURATION_TYPE_TEMPORARY, (EffectShareDamage((oTarget), 10, 1)), OBJECT_SELF, TurnsToSeconds(5)));
DelayCommand(0.3, SetImmortal(oTarget, TRUE));
DelayCommand(0.5, ApplyThirdEffect(oTarget)); //checks if the Jar is destroyed, if yes the caster is killed
}
//Select the next target within the spell shape.
oTarget = GetNextObjectInShape(SHAPE_SPHERE, RADIUS_SIZE_MEDIUM, lTarget, TRUE, OBJECT_TYPE_CREATURE );
}
}
void main()
{
if (!X2PreSpellCastCode())
{
// If code within the PreSpellCastHook (i.e. UMD) reports FALSE, do not run this spell
return;
}
//Declare major variables
int nMetaMagic = GetMetaMagicFeat();
int nCasterLevel = GetCasterLevel(OBJECT_SELF);
int nDuration = 50;
//nDuration = 24;
effect eSummon;
//Make metamagic extend check
if (nMetaMagic == METAMAGIC_EXTEND)
{
nDuration = nDuration *2; //Duration is +100%
}
eSummon = EffectSummonCreature("AA_MagicJar", VFX_HIT_SPELL_SUMMON_CREATURE);
//Apply summon effect and VFX impact.
ApplyEffectAtLocation(DURATION_TYPE_TEMPORARY, eSummon, GetSpellTargetLocation(), RoundsToSeconds(nDuration));
DelayCommand(0.3, ApplySecondEffect());
}