#include "jhr_i0_pipe"

void main()
{
    object oItem = GetItemActivated();
    object oActivator = GetItemActivator();
    object oTarget = GetItemActivatedTarget();
    string sItemTag = GetTag(oItem);
    location lTargetLoc = GetItemActivatedTargetLocation();

    // DMFI: Converaation toggler
    if (sItemTag == "JHR_IT_CONVERSATIONTOGGLER")
    {
        // DMFI: Toggle "bConversationEnabled"
        if (GetLocalInt(oTarget, "bConversationEnabled") == 0)
        {
            SetLocalInt(oTarget, "bConversationEnabled", 1);
            SendMessageToAllDMs("Conversation enabled: " + GetTag(oTarget));
        }
        else
        {
            SetLocalInt(oTarget, "bConversationEnabled", 0);
            SendMessageToAllDMs("Conversation disabled: " + GetTag(oTarget));
        }
    }
    if (sItemTag == "JHR_IT_PLOTWAND")
    {
        SetLocalObject(GetModule(), "oPlotTarget", oTarget);
        SetLocalLocation(GetModule(), "oPlotTargetLoc", lTargetLoc);
        //Make the activator start a conversation with itself
        AssignCommand(oActivator, ActionStartConversation(oActivator, "jhr_plotwand", TRUE));
    }

    if (sItemTag == "jhr_it_pipe")
    {
        SmokePipe(oActivator);
    }

    if ((sItemTag == "jhr_map") && (GetIsPC(oActivator)))
    {

        ActionJumpToObject(GetObjectByTag("JHR_WP_MAP"));
    }
    if (sItemTag == "DMsHelper")
    {
      // Test to make sure the activator is a DM, or is a DM
      // controlling a creature.
      if(GetIsDM(oActivator) != TRUE)
      {
         object oTest = GetFirstPC();
         string sTestName = GetPCPlayerName(oActivator);
         int nFound = FALSE;
         while (GetIsObjectValid(oTest) && (! nFound))
         {
            if (GetPCPlayerName(oTest) == sTestName)
            {
               if(GetIsDM(oTest))
               {
                  nFound = TRUE;
               }
               else
               {
                  DestroyObject(oItem);
                  SendMessageToPC(oActivator,"You are mortal and this is not yours!");
                  return;
               }
            }
            oTest=GetNextPC();
         }
      }
      // get the wand's activator and target, put target info into local vars on activator
      object oMyActivator = GetItemActivator();
      object oMyTarget = GetItemActivatedTarget();
      SetLocalObject(oMyActivator, "dmwandtarget", oMyTarget);
      location lMyLoc = GetItemActivatedTargetLocation();
      SetLocalLocation(oMyActivator, "dmwandloc", lMyLoc);

      //Make the activator start a conversation with itself
      AssignCommand(oMyActivator, ActionStartConversation(oMyActivator, "dmwand", TRUE));
      return;
   }

   if (sItemTag == "AutoFollow")
   {
      object oTarget = GetItemActivatedTarget();

      if(GetIsObjectValid(oTarget))
      {
         AssignCommand ( oActivator, ActionForceFollowObject(oTarget));
      }
      return;
   }

   if (sItemTag == "WandOfFX")
   {

       // get the wand's activator and target, put target info into local vars on activator
      object oDM = GetItemActivator();
      object oMyTarget = GetItemActivatedTarget();
      SetLocalObject(oDM, "FXWandTarget", oMyTarget);
      location lTargetLoc = GetItemActivatedTargetLocation();
      SetLocalLocation(oDM, "FXWandLoc", lTargetLoc);

      object oTest=GetFirstPC();
      string sTestName = GetPCPlayerName(oDM);
      // Test to make sure the activator is a DM, or is a DM
      // controlling a creature.

      if(GetIsDM(oDM) != TRUE)
      {
         object oTest = GetFirstPC();
         string sTestName = GetPCPlayerName(oDM);
         int nFound = FALSE;
         while (GetIsObjectValid(oTest) && (! nFound))
         {
            if (GetPCPlayerName(oTest) == sTestName)
            {
               if(GetIsDM(oTest))
               {
                  nFound = TRUE;
               }
               else
               {
                  DestroyObject(oItem);
                  SendMessageToPC(oDM,"You are mortal and this is not yours!");
                  return;
               }
            }
            oTest=GetNextPC();
         }
      }

      //Make the activator start a conversation with itself
      AssignCommand(oDM, ActionStartConversation(oDM, "fxwand", TRUE));
      return;

   }
   if (sItemTag == "EmoteWand")
   {
      AssignCommand(oActivator, ActionStartConversation(oActivator, "emotewand", TRUE));
      return;
   }
}
