// rts_it_op13
#include "rtsh_multiplay"

void fnHourlyConsumption(object oNPC)
{ // NPC Should consume 10 Mana Per hour
    string sTID=GetLocalString(oNPC,"sTeamID");
    int nMana=fnGetTeamMana(oNPC);
    if (nMana>10)
    { // consume mana
        nMana=nMana-10;
        fnSetTeamMana(oNPC,nMana);
        DelayCommand(HoursToSeconds(1),fnHourlyConsumption(oNPC));
    } // consume mana
    else
    { // despawn
        effect eVFX=EffectVisualEffect(VFX_IMP_UNSUMMON);
        ApplyEffectAtLocation(DURATION_TYPE_INSTANT,eVFX,GetLocation(oNPC));
        DelayCommand(1.0,DestroyObject(oNPC));
    } // despawn
} // fnHourlyConsumption()

void main()
{
    object oPC=GetItemActivator();
    object oItem=GetItemActivated();
    string sRes="merop13";
    object oCr;
    object oDummy;
    object oWP;
    int nMana=fnGetTeamMana(oPC);
    string sID=GetLocalString(oPC,"sTeamID");
    if (sID=="UNC")
    { // allowed team
      if (nMana>199)
      { // sufficient mana
        oWP=GetWaypointByTag(sID+"_RESOURCES");
        effect eVFX=EffectVisualEffect(VFX_FNF_SUMMON_MONSTER_1);
        ApplyEffectAtLocation(DURATION_TYPE_INSTANT,eVFX,GetLocation(oPC));
        oCr=CreateObject(OBJECT_TYPE_CREATURE,sRes,GetLocation(oPC));
        oDummy=GetObjectByTag(sID+"_PROXY");
        ChangeFaction(oCr,oDummy);
        //DelayCommand(1.0,DestroyObject(oDummy));
        SetLocalString(oCr,"sTeamID",sID);
        AssignCommand(oCr,DelayCommand(HoursToSeconds(1),fnHourlyConsumption(oCr)));
        nMana=nMana-200;
        fnSetTeamMana(oPC,nMana);
      } // sufficient mana
      else { SendMessageToPC(oPC,"200 mana is required to activate this item."); }
    } // allowed team
    else { SendMessageToPC(oPC,"This item is only beneficial to the unclean team."); }
}