#include "bleeding_config"
#include "x3_inc_horse"
#include "nwnx_webhook"

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 oPC=GetEnteringObject();
    ExecuteScript("x3_mod_pre_enter",OBJECT_SELF); // Override for other skin systems
    if ((GetIsPC(oPC)||GetIsDM(oPC))&&!GetHasFeat(FEAT_HORSE_MENU,oPC))
    { // add horse menu
        HorseAddHorseMenu(oPC);
        if (GetLocalInt(GetModule(),"X3_ENABLE_MOUNT_DB"))
        { // restore PC horse status from database
            DelayCommand(2.0,HorseReloadFromDatabase(oPC,X3_HORSE_DATABASE));
        } // restore PC horse status from database
    } // add horse menu
    if (GetIsPC(oPC))
    { // more details
        // restore appearance in case you export your character in mounted form, etc.
        if (!GetSkinInt(oPC,"bX3_IS_MOUNTED")) HorseIfNotDefaultAppearanceChange(oPC);
        // pre-cache horse animations for player as attaching a tail to the model
        HorsePreloadAnimations(oPC);
        DelayCommand(3.0,HorseRestoreHenchmenLocations(oPC));
    } // more details
	
//:: Add PRC journal entries
    AddJournalQuestEntry("JRNL_XPCHART", 1, oPC, FALSE, FALSE, FALSE);
    AddJournalQuestEntry("JRNL_LA_BUYOFF", 1, oPC, FALSE, FALSE, FALSE);
	AddJournalQuestEntry("JRNL_PRC8", 1, oPC, FALSE, FALSE, FALSE);

  object oInvItem;
  int nPCxp = GetXP(oPC);

    if (GetLocalInt(oPC, "Initialized")) {
        int iLastHP;

        if (GetLocalInt(oPC, "PlayerHealth") == PC_HEALTH_DYING) {
            // They left while bleeding so just make em dead
            iLastHP = -10;
        }
        else {
            // Set them back to whatever HitPoints they had when they left...
            iLastHP = GetLocalInt(oPC, "LastHitPoints");
        }

        effect eDamage = EffectDamage(GetCurrentHitPoints(oPC) - iLastHP, DAMAGE_TYPE_MAGICAL, DAMAGE_POWER_PLUS_FIVE);
        ApplyEffectToObject(DURATION_TYPE_INSTANT, eDamage, oPC);

    }
    else {
        // First time they signed on
        SetLocalInt(oPC, "Initialized", TRUE);
        SetLocalInt(oPC, "LastHitPoints", GetCurrentHitPoints(oPC));
        if(nPCxp == 0) {
          CreateItemOnObject("noobsguidetoeter", oPC);
//          CreateItemOnObject("readme", oPC);
        }
        CreateItemOnObject("warofthemarks", oPC);
        //:: CreateItemOnObject("serverisshutting", oPC); //:: not shutting down now!

    }

    oInvItem = GetFirstItemInInventory(oPC);

    while (GetIsObjectValid(oInvItem) != 0)
    {

      if (GetTag(oInvItem) == "FalseMark") {
          DestroyObject(oInvItem);
          RemoveAllEffects(oPC);
      }

      if (GetTag(oInvItem) == "MarkofGamlee") {
          DestroyObject(oInvItem);
          RemoveAllEffects(oPC);
      }

      if (GetTag(oInvItem) == "MarkofOron") {
          DestroyObject(oInvItem);
          RemoveAllEffects(oPC);
      }

      if (GetTag(oInvItem) == "MarkofMaro") {
          DestroyObject(oInvItem);
          RemoveAllEffects(oPC);
      }

      if (GetTag(oInvItem) == "MarkofZool") {
          DestroyObject(oInvItem);
          RemoveAllEffects(oPC);
      }

/*       if (GetTag(oInvItem) == "nw_it_mbelt012") {
          DestroyObject(oInvItem);
      }

      if (GetTag(oInvItem) == "nw_it_mbelt013") {
          DestroyObject(oInvItem);
      }

      if (GetTag(oInvItem) == "nw_it_mbelt014") {
          DestroyObject(oInvItem);
      } */

      oInvItem = GetNextItemInInventory(oPC);

    }

    oInvItem = GetItemInSlot(INVENTORY_SLOT_BELT, oPC);

/*     if (GetTag(oInvItem) == "nw_it_mbelt012") {
        DestroyObject(oInvItem);
    }

    if (GetTag(oInvItem) == "nw_it_mbelt013") {
        DestroyObject(oInvItem);
    }

    if (GetTag(oInvItem) == "nw_it_mbelt014") {
        DestroyObject(oInvItem);
    } */

}

