/*--------------------------------------------------------

Script Name: savecharacters2
----------------------------------------------------------
Created By: Genisys(Guile)
Created On: 2/09/09
----------------------------------------------------------


----------------------------------------------------------*/

//This checks to see if the player is polymorphed...
int IsShifterMorphed(object oPC)
{
    effect ef = GetFirstEffect(oPC);
    int iShifter = FALSE;
    //if (GetLevelByClass(CLASS_TYPE_DRUID,oPC)>0)  //Is Shifter, search the PolyEff
    while( GetEffectType(ef) != EFFECT_TYPE_INVALIDEFFECT && iShifter == FALSE)
    {
        if ( GetEffectType(ef) == EFFECT_TYPE_POLYMORPH )
            iShifter = TRUE;

        ef = GetNextEffect(oPC);
    }
    return iShifter;
}

void main()
{

object oPP = GetFirstPC();
string sName = GetStringLeft(GetName(oPP), 20);
location lSaved = GetLocation(oPP);
int MULTI_PLAYER = GetLocalInt(GetModule(), "multi");

while(GetIsObjectValid(oPP))
{
//If they are in the guild...
if(GetItemPossessedBy(oPP, "guildpass")!=OBJECT_INVALID)
{
 //Let's make sure their area is valid!
 if(GetArea(GetAreaFromLocation(lSaved))!=OBJECT_INVALID)
 {

  object oGuild = GetItemPossessedBy(oPP, "guildstone");

  //Store the PC's location, so they can come back here after relogging
  if(oGuild != OBJECT_INVALID)
  {
   SetCampaignLocation("LOCATIONS", GetName(oGuild), lSaved, oPP);
   SendMessageToPC(oPP, "Location Saved");
  }
 }
 else
 {
  SendMessageToPC(oPP, "Your location was NOT saved, you need to rest to save your location.");
 }
}

//If the PC is not polymorphed save their character as well!
if(IsShifterMorphed(oPP)==FALSE)
{
 if(GetAreaFromLocation(lSaved)!=OBJECT_INVALID)
 {
  if(MULTI_PLAYER)
  {
   ExportSingleCharacter(oPP);
  }
 }
}
else
 {
  SendMessageToPC(oPP, "Your character was not saved because you are polymorphed.");
 }

oPP = GetNextPC();
}

SendMessageToPC(GetPCSpeaker(), "All characters on the server have been saved.");
SendMessageToAllDMs("All characters saved at Rowan Tree.");
}