//::///////////////////////////////////////////////
//:: Summon Mephit
//:: NW_S1_SummMeph
//:: Copyright (c) 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
    Summons a Mephit, type determined by caster
*/
//:://////////////////////////////////////////////
//:: Created By: Preston Watamaniuk
//:: Created On: Aug 14, 2001
//:://////////////////////////////////////////////
#include "prc_inc_spells"

// Applies a 1-hour cooldown to the summoned mephit
void WasteSummonSpell()
{
    object oSummoned = OBJECT_SELF; // The summoned creature
	
	location lSelf = GetLocation(oSummoned);
	
	effect eCooldown = EffectSpellFailure(100);
	
    eCooldown = EffectLinkEffects(SupernaturalEffect(eCooldown), TagEffect(eCooldown, "NO_SUMMON"));
	
    ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eCooldown, oSummoned, RoundsToSeconds(2));
	
	AssignCommand(oSummoned, ActionCastSpellAtLocation(378/*SUMMON_MEPHIT*/, lSelf, METAMAGIC_ANY, FALSE, PROJECTILE_PATH_TYPE_DEFAULT, TRUE));
	
}


void main()
{
    object oCaster = OBJECT_SELF; 
    string sCasterResRef = GetResRef(oCaster); 

    // Roll d% for the 25% chance of summoning
    int nRoll = d100(1);
    if (nRoll > 25)
    {
        // Create a puff of smoke at the caster's location and play a fizzling sound
        location lCaster = GetLocation(oCaster);
        effect eSmoke = EffectVisualEffect(VFX_IMP_MAGIC_RESISTANCE_USE); 
        ApplyEffectAtLocation(DURATION_TYPE_INSTANT, eSmoke, lCaster);

        // Play a sound effect to simulate the fizzle
        PlaySound("sff_spellfail");

        return;
    }

    // Summon the mephit using the caster's ResRef
    effect eSummon = EffectSummonCreature(sCasterResRef, VFX_FNF_SUMMON_MONSTER_2);

    // Handle metamagic: Extend Spell doubles the duration
    int nMetaMagic = PRCGetMetaMagicFeat();
    float fDuration = HoursToSeconds(24);
    if (nMetaMagic & METAMAGIC_EXTEND) fDuration *= 2;

    // Apply the summoning effect at the target location
    location lTarget = PRCGetSpellTargetLocation();
    ApplyEffectAtLocation(DURATION_TYPE_TEMPORARY, eSummon, lTarget, fDuration);

    // Find the summoned creature and apply a cooldown marker
    DelayCommand(0.1, AssignCommand(GetAssociate(ASSOCIATE_TYPE_SUMMONED, oCaster), WasteSummonSpell()));
}





/* void main()
{
    //Declare major variables
    int nMetaMagic = GetMetaMagicFeat();
    effect eSummon = EffectSummonCreature("NW_S_MEPSTEAM",VFX_FNF_SUMMON_MONSTER_1);
   // effect eVis = EffectVisualEffect(VFX_FNF_SUMMON_MONSTER_1);
    //Apply the VFX impact and summon effect
    //ApplyEffectAtLocation(DURATION_TYPE_TEMPORARY, eVis, GetSpellTargetLocation());
    ApplyEffectAtLocation(DURATION_TYPE_TEMPORARY, eSummon, GetSpellTargetLocation(), HoursToSeconds(24));
} */
