//::///////////////////////////////////////////////
//:: OnHitCastSpell Deafening Clang
//:: x2_s3_deafclng
//:: Copyright (c) 2003 Bioware Corp.
//:://////////////////////////////////////////////
/*
   * OnHit 100% chance to deafen enemy for
     1 round per casterlevel

   * Fort Save DC 10+CasterLevel negates

   * Standard level used by the deafening clang
     spellscript is 5.


*/
//:://////////////////////////////////////////////
//:: Created By: Georg Zoeller
//:: Created On: 2003-09-19
//:://////////////////////////////////////////////

#include "x2_inc_switches"
#include "x0_i0_spells"
#include "jx_inc_magic"
#include "x2_inc_spellhook"

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

void mainSpell()
{
	if (!X2PreSpellCastCode()) { JXPostSpellCastCode(); return; }



   object oItem;        // The item casting triggering this spellscript
   object oSpellTarget; // On a weapon: The one being hit. On an armor: The one hitting the armor
   object oSpellOrigin; // On a weapon: The one wielding the weapon. On an armor: The one wearing an armor

   // fill the variables
   oSpellOrigin = OBJECT_SELF;
   oSpellTarget = JXGetSpellTargetObject();
   oItem        =  GetSpellCastItem();
   int iCasterLevel = JXGetCasterLevel(oSpellOrigin);

   if (GetIsObjectValid(oItem))
   {
      // you can not be deafened if you already can not hear.
      if (!GetHasSpellEffect(JXGetSpellId(),oSpellTarget) &&!GetHasSpellEffect(SPELL_MASS_BLINDNESS_AND_DEAFNESS,oSpellTarget)  && !GetHasSpellEffect(SPELL_BLINDNESS_AND_DEAFNESS,oSpellTarget) )
      {
              if (!ResistSpell(oSpellOrigin,oSpellTarget) == 0)
              {
                  int nDC= iCasterLevel+10;
                  if (MySavingThrow(SAVING_THROW_FORT,oSpellTarget, nDC,SAVING_THROW_TYPE_SONIC,oSpellOrigin) ==0)
                  {
                      int nRounds = iCasterLevel;
                      effect eDeaf = EffectDeaf();
                      effect eVis = EffectVisualEffect(VFX_IMP_BLIND_DEAF_M);
                      JXApplyEffectToObject(DURATION_TYPE_TEMPORARY,eDeaf,oSpellTarget,RoundsToSeconds(nRounds));
                      JXApplyEffectToObject(DURATION_TYPE_INSTANT,eVis,oSpellTarget);
                      FloatingTextStrRefOnCreature(85388,oSpellTarget,FALSE);
                }
           }
        }

   }

	JXPostSpellCastCode();
}
