//#include "_persist_01a"

void main()
{
 object oPC = GetLastOpenedBy();
 //int iTailorSkill = GetTokenPair(oPC,13,9); // Tailoring  (Credit Tony Edwards for catching a mis-typed token value here.. was originally using weaponcraft skill to determine tailor patterns.  Thx Tony ;)
 int iTailorSkill = GetCampaignInt("UOACraft","iTailorSkill",oPC);
 int iTailorChance = iTailorSkill;

 if (GetItemPossessedBy(oPC,"NoDrop_SkillLogBook")==OBJECT_INVALID)
   {
    CreateItemOnObject("skilllogbook",oPC,1);
   }

 if (iTailorChance < 350)
  {
   iTailorChance = GetAbilityScore(oPC,ABILITY_DEXTERITY)*5;
   iTailorChance = iTailorChance+(GetAbilityScore(oPC,ABILITY_STRENGTH)*3);
   iTailorChance = iTailorChance+(GetAbilityScore(oPC,ABILITY_WISDOM)*2);
   iTailorChance = iTailorChance*3;
   if (iTailorChance>350)iTailorChance=350;
   if (iTailorSkill > iTailorChance) iTailorChance=iTailorSkill;
  }

 int iClothType = GetLocalInt(oPC,"iUseClothType");


 if (iClothType != 0)CreateItemOnObject("flagswitch048",OBJECT_SELF,1);
 if (iClothType != 1)CreateItemOnObject("flagswitch049",OBJECT_SELF,1);
 if (iClothType != 2)CreateItemOnObject("flagswitch050",OBJECT_SELF,1);

 if (iClothType ==2) iTailorChance = iTailorChance - 300;
 if (iClothType ==3) iTailorChance = iTailorChance - 600;


 CreateItemOnObject("p_clothing_001",OBJECT_SELF,1);   // Adept's Tunic
 CreateItemOnObject("p_clothing_003",OBJECT_SELF,1);   // Assassin's Garb
 CreateItemOnObject("p_clothing_004",OBJECT_SELF,1);   // Barabrian's Outfit
 CreateItemOnObject("p_clothing_005",OBJECT_SELF,1);   // Bard's Tunic
 CreateItemOnObject("p_clothing_006",OBJECT_SELF,1);   // Commoner Outfit
 CreateItemOnObject("p_clothing_007",OBJECT_SELF,1);   // Commoner Tunic
 CreateItemOnObject("p_clothing_008",OBJECT_SELF,1);   // Conjurer's Robe
 CreateItemOnObject("p_clothing_009",OBJECT_SELF,1);   // Gladiator's Outfit
 CreateItemOnObject("p_clothing_010",OBJECT_SELF,1);   // Illusionists Robe
 CreateItemOnObject("p_clothing_011",OBJECT_SELF,1);   // Jester's Outfit
 CreateItemOnObject("p_clothing_012",OBJECT_SELF,1);   // Monk's Outfit
 CreateItemOnObject("p_clothing_013",OBJECT_SELF,1);   // Necromancer's Robe
 CreateItemOnObject("p_clothing_014",OBJECT_SELF,1);   // Noble Guardsman Tunic
 CreateItemOnObject("p_clothing_015",OBJECT_SELF,1);   // Noble's Outfit
 CreateItemOnObject("p_clothing_016",OBJECT_SELF,1);   // Noble's Tunic
 CreateItemOnObject("p_clothing_017",OBJECT_SELF,1);   // Paladin's Tunic
 CreateItemOnObject("p_clothing_018",OBJECT_SELF,1);   // Performer's Outfit
 CreateItemOnObject("p_clothing_019",OBJECT_SELF,1);   // Priest's Robe
 CreateItemOnObject("p_clothing_020",OBJECT_SELF,1);   // Rogue's Tunic
 CreateItemOnObject("p_clothing_021",OBJECT_SELF,1);   // Soldier's Tunic
 CreateItemOnObject("p_clothing_022",OBJECT_SELF,1);   // Sorcerer's Robe
 CreateItemOnObject("p_clothing_023",OBJECT_SELF,1);   // Squire's Tunic
 CreateItemOnObject("p_clothing_024",OBJECT_SELF,1);   // Urchin Rags
 CreateItemOnObject("p_clothing_025",OBJECT_SELF,1);   // Vagabond Rags
 CreateItemOnObject("p_clothing_026",OBJECT_SELF,1);   // Veteran's Outfit
 CreateItemOnObject("p_clothing_027",OBJECT_SELF,1);   // Warrior's Tunic
 CreateItemOnObject("p_clothing_028",OBJECT_SELF,1);   // Wizard's Robe
 CreateItemOnObject("p_clothing_029",OBJECT_SELF,1);   // Woodsman's Outfit






  if (iTailorChance>900)CreateItemOnObject("p_clothing_002",OBJECT_SELF,1);     // Adventurer's robe (expensive)


  // Search for and destroy any hidden 'body bags' from prior incarnations of this placeable
 object oSearchForBag = GetNearestObjectByTag("Body Bag",OBJECT_SELF,1);
 if (oSearchForBag == OBJECT_INVALID)return;
 object oBagItem = OBJECT_INVALID;
 if (GetDistanceToObject(oSearchForBag)<= 0.2)
  {
   //SendMessageToPC(GetFirstPC(),"Body bag found.. destroying contents..");
   oBagItem = GetFirstItemInInventory(oSearchForBag);
   while (oBagItem != OBJECT_INVALID)
    {
     //SendMessageToPC(GetFirstPC(),"Destroying : "+GetName(oBagItem));
     DestroyObject(oBagItem);
     oBagItem = GetNextItemInInventory(oSearchForBag);
    }
   DestroyObject(oSearchForBag,1.0);
  }
}