// RemoveAllEffects()
//////////////////////////////////////////////////////////////
// Created By: Brenon Holmes
// Created On: Jun/09/02
// Description: Removes all non-permanent/innate/equipped
//              effects from the specified player.
//////////////////////////////////////////////////////////////
#include "x2_inc_switches"

void RemoveAllEffects( object oPlayer )
{
    effect eEffect;
    eEffect = GetFirstEffect(oPlayer);

    while ( GetIsEffectValid(eEffect) == TRUE )
    {
        if ( GetEffectDurationType(eEffect) == DURATION_TYPE_TEMPORARY ||
             GetEffectDurationType(eEffect) == DURATION_TYPE_PERMANENT )
        {
            RemoveEffect(oPlayer,eEffect);
        }

        eEffect = GetNextEffect(oPlayer);
    }
}

void main()
{
     object oItem = GetModuleItemLost();
     // * Generic Item Script Execution Code
     // * If MODULE_SWITCH_EXECUTE_TAGBASED_SCRIPTS is set to TRUE on the module,
     // * it will execute a script that has the same name as the item's tag
     // * inside this script you can manage scripts for all events by checking against
     // * GetUserDefinedItemEventNumber(). See x2_it_example.nss
     if (GetModuleSwitchValue(MODULE_SWITCH_ENABLE_TAGBASED_SCRIPTS) == TRUE)
     {
        SetUserDefinedItemEventNumber(X2_ITEM_EVENT_UNACQUIRE);
        int nRet =   ExecuteScriptAndReturnInt(GetUserDefinedItemEventScriptName(oItem),OBJECT_SELF);
        if (nRet == X2_EXECUTE_SCRIPT_END)
        {
           return;
        }

     }

  object oPC = GetModuleItemLostBy();
  string sItemTag = GetTag(oItem);
  int nYes = 0;

  if(sItemTag == "FalseMark")
    nYes = 1;
  if(sItemTag == "MarkofOron")
    nYes = 1;
  if(sItemTag == "MarkofGamlee")
    nYes = 1;
  if(sItemTag == "MarkofZool")
    nYes = 1;
  if(sItemTag == "MarkofMaro")
    nYes = 1;

  if(nYes == 1) { // if item lost was a mark, check to see if that was the last one


    object oInvItem = GetFirstItemInInventory(oPC);
    nYes = 0;
    while (GetIsObjectValid(oInvItem) == TRUE) {

      sItemTag = GetTag(oInvItem);

      if(sItemTag == "FalseMark")
        nYes = 1;
      if(sItemTag == "MarkofOron")
        nYes = 1;
      if(sItemTag == "MarkofGamlee")
        nYes = 1;
      if(sItemTag == "MarkofZool")
        nYes = 1;
      if(sItemTag == "MarkofMaro")
        nYes = 1;

      if(oInvItem == oItem)
        nYes = 0;

      oInvItem = GetNextItemInInventory(oPC);

    }


    if(nYes == 0) {  // if there are no marks in inv, remove flag effect

//      AssignCommand(oPC, DelayCommand(3.0, RemoveAllEffects(oPC)));
      RemoveAllEffects(oPC);
    }

  }

}
