//::///////////////////////////////////////////////
//:: Divine Shield
//:: x0_s2_divshield.nss
//:: Copyright (c) 2002 Bioware Corp.
//:://////////////////////////////////////////////
/*
    Up to [turn undead] times per day the character may add his Charisma bonus to his armor
    class for a number of rounds equal to the Charisma bonus.
*/
//:://////////////////////////////////////////////
//:: Created By: Brent
//:: Created On: Sep 13, 2002
//:://////////////////////////////////////////////
#include "x0_i0_spells"

void main()
{

   if (!GetHasFeat(FEAT_TURN_UNDEAD, OBJECT_SELF))
   {
        SpeakStringByStrRef(40550);
   }
   else
   if(GetHasFeatEffect(414) == FALSE)
   {
        //Declare major variables
        object oTarget = GetSpellTargetObject();
        int nLevel = GetCasterLevel(OBJECT_SELF);

        effect eVis = EffectVisualEffect(VFX_IMP_SUPER_HEROISM);
        effect eDur = EffectVisualEffect(VFX_DUR_PROT_PREMONITION);

        int nCharismaBonus = GetAbilityModifier(ABILITY_CHARISMA);

        // *** Tarashon making duration be minimum 10 rounds for Alangara - New Dawn PW *** //

        int nDuration = 10;

        // *** Tarashon making duration be minimum 15 rounds if player has Extend Spell Feat *** //

        object oPC;

        oPC = OBJECT_SELF;

        if ( GetHasFeat(FEAT_EXTEND_SPELL, oPC) )
        {
        nDuration = 15;
        }

        // *** Tarashon setting charisma bonus to minimum +4 *** //

        if (nCharismaBonus <4)
        {
        nCharismaBonus = 4;
        }

        // *** Tarashon setting charisma bonus to maximum +10 *** //

        if (nCharismaBonus >10)
        {
        nCharismaBonus = 10;
        }

        // *** Tarashon adding Charisma Modifier to duration *** //

        nDuration = nDuration + nCharismaBonus;

        nDuration = nDuration*3;

        // *** Tarashon done, except durtion is altered now to nDuration instead of nCharismaBonus *** //

        effect eAC = EffectACIncrease(nCharismaBonus, AC_SHIELD_ENCHANTMENT_BONUS );

        effect eLink = EffectLinkEffects(eAC, eDur);

        eLink = SupernaturalEffect(eLink);

         // * Do not allow this to stack
        RemoveEffectsFromSpell(oTarget, GetSpellId());

        // *** Create the potions is user is paladin level 15+ *** //

         if (GetLevelByClass(CLASS_TYPE_PALADIN, oPC) >= 15)
         //if (GetHitDice(oPC) >= 15)
         {
          CreateItemOnObject("divine_shield", oPC);
         }

         // *** Create the potions is user is BlackGuard level 15+ *** //

         if (GetLevelByClass(CLASS_TYPE_BLACKGUARD, oPC) >= 15)
         //if (GetHitDice(oPC) >= 15)
         {
          CreateItemOnObject("divine_shield", oPC);
         }

          // *** End of create potion *** //

        //Fire cast spell at event for the specified target
        SignalEvent(oTarget, EventSpellCastAt(OBJECT_SELF, 474, FALSE));

        //Apply Link and VFX effects to the target
        ApplyEffectToObject(DURATION_TYPE_TEMPORARY, eLink, oTarget, RoundsToSeconds(nDuration));
        ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, oTarget);

        DecrementRemainingFeatUses(OBJECT_SELF, FEAT_TURN_UNDEAD);
    }
}