//:://///////////////////////////////////////////////////////////////////////
//:: General Treasure Spawn Script   MEDIUM
//:: Copyright (c) 2001 Bioware Corp.
//:://////////////////////////////////////////////
/*
    Spawns in general purpose treasure, usable
    by all classes.
*/
//::///////////////////////////////////////////////
//:: Created By:   Brent
//:: Created On:   February 26 2001
//:://////////////////////////////////////////////////
#include "NW_O2_CONINCLUDE"
#include "NW_I0_GENERIC"
#include "jw_privates_inc"

// Creates some sort of herb or berry
void MakeBerry();

void main()

{

     object oLastOpener = GetLastOpener();

    if (GetIsPC(oLastOpener))
    {
     SetTarget(oLastOpener);
     SpeakString("NW_ATTACK_MY_TARGET", TALKVOLUME_SILENT_TALK);
    }


    // sets "NW_DO_ONCE" back to 0 if nSpawnDelay has passed
    int nCurrentHour = (GetCalendarYear()-1)*12*28*24 +
    (GetCalendarMonth()-1)*28*24 +
    (GetCalendarDay()-1)*24 +
    GetTimeHour();
    int nLastSpawnHour = GetLocalInt(OBJECT_SELF,"LAST_SPAWN_HOUR");
    int nSpawnDelay = 0;
    if (nCurrentHour > (nLastSpawnHour + nSpawnDelay))
    {
       SetLocalInt(OBJECT_SELF,"NW_DO_ONCE",0);
    }

    //return if time has not passed yet
    if (GetLocalInt(OBJECT_SELF,"NW_DO_ONCE") != 0)
    {
       return;
    }

    // with a chance of 50% or if the container is empty, treasure will be generated
    int nRandom = d3();
    if (nRandom > 1)
    {
        RemoveItems(OBJECT_SELF);
        MakeBerry();
    }

    SetLocalInt(OBJECT_SELF,"NW_DO_ONCE",1);
    SetLocalInt(OBJECT_SELF,"LAST_SPAWN_HOUR",nCurrentHour);
    SpeakString("NW_ATTACK_MY_TARGET", TALKVOLUME_SILENT_TALK);


}

void MakeBerry ()
{
string sString;
if (d10()==1)
 {
  sString="jw_harpherb"+IntToString(Random(7)+1);
 }
else
 {
  sString="jw_berry";
 }
CreateItemOnObject(sString,OBJECT_SELF,1);
}