#include "x2_inc_itemprop"
#include "x3_inc_string"

void main()
{
 ActionPauseConversation();
 object oPC = GetPCSpeaker();
 TakeGoldFromCreature(1000000, oPC, TRUE);
 object oForge = GetNearestObjectByTag ("WeaponForge", OBJECT_SELF, 1);
 object oOldWeapon = GetFirstItemInInventory(oForge);
 string sItemTemplate1 = "agoad";
 effect eVis = EffectVisualEffect(VFX_IMP_LIGHTNING_M);
 effect eVis2 = EffectVisualEffect(VFX_IMP_DIVINE_STRIKE_FIRE);
 effect eVis3 = EffectVisualEffect(VFX_IMP_FROST_L);
 string sOldWeapon = GetName(oOldWeapon);
 string sNewWeaponName = StringToRGBString(sOldWeapon+" Reforged", "730");

 if (!GetIsObjectValid(oOldWeapon)) return;
 AssignCommand (oForge, ActionLockObject (oForge));

//Get the first itemproperty on the weapon
itemproperty ipLoop=GetFirstItemProperty(oOldWeapon);
object oNewWeapon = CreateItemOnObject (sItemTemplate1, oForge, 1);
 //object oNewWeapon = GetNextItemInInventory (oForge);

//Loop for as long as the ipLoop variable is valid
 while (GetIsItemPropertyValid(ipLoop))
   {
   //Add itemprops to new weapon
   IPSafeAddItemProperty(oNewWeapon, ipLoop);

   //Next itemproperty on the list...
   ipLoop=GetNextItemProperty(oOldWeapon);
   }

  SetName(oNewWeapon, sNewWeaponName);
  DestroyObject (oOldWeapon);
  ActionPlayAnimation(ANIMATION_LOOPING_CONJURE2, 1.0, 5.5);
  DelayCommand(1.0, ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis, oForge));
  DelayCommand(3.0, ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis2, oForge));
  DelayCommand(5.0, ApplyEffectToObject(DURATION_TYPE_INSTANT, eVis3, oForge));
  DelayCommand(6.5, ActionSpeakString("It is done"));
  AssignCommand(oForge, DelayCommand (8.0, ActionUnlockObject (oForge)));
  ActionResumeConversation();
 }