////////////////////////////////////////////////////////////////////////////////
// Spells out the Wazoo - SPELL PLANE SHIFT
// By Deva Bryson Winblood. 12/18/2003
////////////////////////////////////////////////////////////////////////////////
/* SETUP REQUIREMENTS FOR THIS SPELL TO BE EFFECTIVE
   It will look for waypoints with the tag PLANESHIFT_<plane> and will ask in a
   conversation which the player wishes the shift to be done to.  If put on
   another target besides the caster it will shift that target.  If put on the
   caster then it will ask them if they wish to shift additional friendly units
   nearby with them.  Planes supported are as follows:
   ASTRAL
   ETHEREAL
   SHADOW
   FIRE
   EARTH
   WATER
   AIR
   POSITIVE
   NEGATIVE
   PRIME   - Prime Material Plane
   CELESTIA
   BYTOPIA
   ELYSIUM
   BEAST  - The Beastlands
   ARBOREA
   YSGARD
   LIMBO
   PANDEMONIUM
   ABYSS#  [ # 1-3 supporting 3 Abyssal areas ]
   CARCERI
   GRAY  - The Gray Waste
   GEHENNA
   HELL   [ First plane of the nine hells Avernus ]
   ACHERON
   MECHANUS
   ARCADIA
   OUTLANDS
   DREAMS   */

#include "x2_inc_spellhook"
#include "prc_inc_spells"

void fnFindSpellCaster()
{
  object oPC=GetLastSpellCaster();
  SetLocalObject(OBJECT_SELF,"oCaster",oPC);
}

void fnSubMain(object oTarget)
{ // finish casting spell
    //object oPC=GetLocalObject(oTarget,"oCaster");
    object oPC=OBJECT_SELF;
    DeleteLocalObject(oTarget,"oCaster");
    SendMessageToPC(oPC,"You cast plane shift at "+GetName(oTarget));
    if (oTarget!=OBJECT_INVALID)
    {
       SetLocalObject(oPC,"oSpellTarget",oTarget);
       AssignCommand(oPC,ClearAllActions(TRUE));
       AssignCommand(oPC,ActionStartConversation(oPC,"wazoo_cv_pshift",TRUE,FALSE));
    }
    else
    {
      SendMessageToPC(oPC,"Not a valid target for plane shift.");
    }
} // finish casting spell

void main()
{
    // Georg Zoeller's SpellHook test
    if (!X2PreSpellCastCode())
    {
      SendMessageToPC(GetLastSpellCaster(),"You could not cast that spell for some reason.");
    // If code within the PreSpellCastHook (i.e. UMD) reports FALSE, do not run this spell
        return;
    }
    // Declare major variables
    int nSpellID = PRCGetSpellId();
    object oTarget=PRCGetSpellTargetObject();
    if (GetPlotFlag(oTarget)==TRUE) return; // do not use plane shift on plot characters
    AssignCommand(oTarget,fnFindSpellCaster());
    DelayCommand(1.0,fnSubMain(oTarget));
}