///////////////////////////////////////////////////////////////////////////////
// wazoo_polyoth - By Deva Bryson Winblood
// Polymorph Other
///////////////////////////////////////////////////////////////////////////////
void main()
{
  object oCaster=GetPCSpeaker();
  object oTarget=GetLocalObject(oCaster,"oSpellTarget");
  int nLevel=GetLocalInt(oCaster,"nCasterLevel");
  effect eEff;
  int nParm=GetLocalInt(oCaster,"nParm");
  int nShape;
  int nSave;
  int bSpellSuccess=TRUE;
  int bDifficultyHardcore=FALSE;
  effect eBeam=EffectBeam(VFX_BEAM_SILENT_MIND,oCaster,BODY_NODE_HAND);
  switch(nParm)
  { // pick shape
    case 0: { nShape=POLYMORPH_TYPE_BADGER; break; }
    case 1: { nShape=POLYMORPH_TYPE_BOAR; break; }
    case 2: { nShape=POLYMORPH_TYPE_CHICKEN; break; }
    case 3: { nShape=POLYMORPH_TYPE_COW; break; }
    case 4: { nShape=POLYMORPH_TYPE_PENGUIN; break; }
    case 5: { nShape=POLYMORPH_TYPE_BROWN_BEAR; break; }
    case 6: { nShape=POLYMORPH_TYPE_WOLF; break; }
    case 7: { nShape=POLYMORPH_TYPE_PANTHER; break; }
    default: break;
  } // pick shape
  // fire beam
  ApplyEffectToObject(DURATION_TYPE_TEMPORARY,eBeam,oTarget,4.0);
  // check for save
  nSave=GetSpellSaveDC();
  if (GetIsPC(oTarget)==TRUE) SendMessageToPC(oTarget,GetName(oCaster)+" cast Polymorph Other spell at you.");
  nSave=FortitudeSave(oTarget,nSave,SAVING_THROW_TYPE_SPELL,oCaster);
  if (nSave>0) bSpellSuccess=FALSE;
  // check for hardcore settings
  if (GetLocalInt(GetModule(),"bHardcoreSpells")==TRUE) bDifficultyHardcore=TRUE;
  if (bSpellSuccess==TRUE)
  { // check resistance
  nSave=ResistSpell(oCaster,oTarget);
  if (nSave>0) bSpellSuccess=FALSE;
  if (nSave==1) SendMessageToPC(oCaster,"Spell was resisted via spell resistance.");
  else if (nSave==2) SendMessageToPC(oCaster,"The target is immune to the spell.");
  else if (nSave==3) SendMessageToPC(oCaster,"The target absorbed the spell.");
  } // check resistance
  if (bSpellSuccess)
  { // spell was successful
    eEff=EffectPolymorph(nShape);
    if (GetIsPC(oTarget)==FALSE||bDifficultyHardcore)
    { // permanent
      DelayCommand(3.5,ApplyEffectToObject(DURATION_TYPE_PERMANENT,eEff,oTarget,10000.0));
    } // permanent
    else
    { // use a duration
      DelayCommand(3.5,ApplyEffectToObject(DURATION_TYPE_TEMPORARY,eEff,oTarget,HoursToSeconds(nLevel)));
    } // use a duration
  } // spell was successful
  else
  {
    SendMessageToPC(oCaster,"*target saved versus that spell*");
    if (GetIsPC(oTarget)==TRUE) SendMessageToPC(oTarget,"*you saved versus the polymorph spell*");
  }
}