// v2.1.0 - Removed HCRHeal function since disabled state was removed from HCR.
// v2.0.0 -
//::////////////////////////////////////////////////////////////////////////////
//:: FileName :  aa_d1_templeheal
//::////////////////////////////////////////////////////////////////////////////
/*
   Fakes the Greater Restoration spell on the PC and all associates.
*/
//::////////////////////////////////////////////////////////////////////////////
#include "hark_i0_hc_lib"
//::////////////////////////////////////////////////////////////////////////////
void FakeRestore(object oTarget)
{
  // Search for and remove negative effects.
  effect eBad = GetFirstEffect(oTarget);
  while (GetIsEffectValid(eBad))
    {
     if (GetEffectType(eBad) == EFFECT_TYPE_ABILITY_DECREASE ||
         GetEffectType(eBad) == EFFECT_TYPE_AC_DECREASE ||
         GetEffectType(eBad) == EFFECT_TYPE_ATTACK_DECREASE ||
         GetEffectType(eBad) == EFFECT_TYPE_DAMAGE_DECREASE ||
         GetEffectType(eBad) == EFFECT_TYPE_DAMAGE_IMMUNITY_DECREASE ||
         GetEffectType(eBad) == EFFECT_TYPE_SAVING_THROW_DECREASE ||
         GetEffectType(eBad) == EFFECT_TYPE_SPELL_RESISTANCE_DECREASE ||
         GetEffectType(eBad) == EFFECT_TYPE_SKILL_DECREASE ||
         GetEffectType(eBad) == EFFECT_TYPE_BLINDNESS ||
         GetEffectType(eBad) == EFFECT_TYPE_DEAF ||
         GetEffectType(eBad) == EFFECT_TYPE_CURSE ||
         GetEffectType(eBad) == EFFECT_TYPE_DISEASE ||
         GetEffectType(eBad) == EFFECT_TYPE_POISON ||
         GetEffectType(eBad) == EFFECT_TYPE_PARALYZE ||
         GetEffectType(eBad) == EFFECT_TYPE_NEGATIVELEVEL)
       { RemoveEffect(oTarget, eBad); }
     eBad = GetNextEffect(oTarget);
    }

  // Apply healing.
  if (GetRacialType(oTarget) != RACIAL_TYPE_UNDEAD)
    {
     int nHeal = GetMaxHitPoints(oTarget) - GetCurrentHitPoints(oTarget);
     effect eHeal = EffectHeal(nHeal);
     if (nHeal > 0)
       { ApplyEffectToObject(DURATION_TYPE_INSTANT, eHeal, oTarget); }
    }

  // Apply visual effect.
  effect eVisual = EffectVisualEffect(VFX_IMP_RESTORATION_GREATER);
  ApplyEffectToObject(DURATION_TYPE_INSTANT, eVisual, oTarget);
}
//::////////////////////////////////////////////////////////////////////////////
void main()
{
  // Pause the conversation and create spell effect.
  ActionPauseConversation();
  ActionCastFakeSpellAtObject(SPELL_GREATER_RESTORATION, OBJECT_SELF);

  // Remove effects from the PC.
  object oPC = GetPCSpeaker();
  ActionDoCommand(FakeRestore(oPC));

  // Remove effects from all henchman and their associates.
  object oHenchman;
  object oTarget;
  int i;
  for (i = 1; i < 6; ++i)
    {
     oHenchman = GetHenchman(oPC);
     while (GetIsObjectValid(oHenchman))
       {
        if (i == 1) oTarget = oHenchman;
        if (i == 2) oTarget = GetAssociate(ASSOCIATE_TYPE_FAMILIAR, oHenchman);
        if (i == 3) oTarget = GetAssociate(ASSOCIATE_TYPE_ANIMALCOMPANION, oHenchman);
        if (i == 4) oTarget = GetAssociate(ASSOCIATE_TYPE_SUMMONED, oHenchman);
        if (i == 5) oTarget = GetAssociate(ASSOCIATE_TYPE_DOMINATED, oHenchman);
        if (GetIsObjectValid(oTarget))
           ActionDoCommand(FakeRestore(oTarget));
        oHenchman = GetHenchman(oHenchman);
       }
    }

  // Remove effects from the PC's Animal Companion, Familiar, etc. if any.
  object oAnimal = GetAssociate(ASSOCIATE_TYPE_ANIMALCOMPANION, oPC);
  if (GetIsObjectValid(oAnimal))
    { ActionDoCommand(FakeRestore(oAnimal)); }
  object oDominated = GetAssociate(ASSOCIATE_TYPE_DOMINATED, oPC);
  if (GetIsObjectValid(oDominated))
    { ActionDoCommand(FakeRestore(oDominated)); }
  object oFamiliar = GetAssociate(ASSOCIATE_TYPE_FAMILIAR, oPC);
  if (GetIsObjectValid(oFamiliar))
    { ActionDoCommand(FakeRestore(oFamiliar)); }
  object oSummoned = GetAssociate(ASSOCIATE_TYPE_SUMMONED, oPC);
  if (GetIsObjectValid(oSummoned))
    { ActionDoCommand(FakeRestore(oSummoned)); }

  // Resume the conversation.
  ActionResumeConversation();
}
//::///////////////////////////////////////////////////////////////////////////
