// v2.0.0 -
//::////////////////////////////////////////////////////////////////////////////
//:: FileName:  hark_onply_lvlup
//::////////////////////////////////////////////////////////////////////////////
/*
   This will need to be added to the On Player Level Up Event Hook of your
  module. The easiest way to do this is to add the following block of code to
  either the preEvent or postEvent hook located in the hc_inc_on_level script.

  It should look something like this.

void postEvent()
{
  object oPC = GetPCLevellingUp();
  object oHench = GetHenchman(oPC);
  if (GetIsObjectValid(oHench))
    { ExecuteScript("hark_onply_lvlup", oHench); }
  return;
}

   This script will auto level up your henchmen when the PC levels up. If you
  choose to not use this script then its not a big deal, just speak with them
  and level them up via a conversation.
*/
//::////////////////////////////////////////////////////////////////////////////
#include "hark_i0_equip"
//::////////////////////////////////////////////////////////////////////////////
void main()
{
  object oMaster = GetRealMaster();
  if (!GetIsObjectValid(oMaster) || !GetIsObjectValid(GetMaster())) { return; }

  // Level up if we are able to.
  if (GetCanLevelUp(oMaster, OBJECT_SELF))
    {
     object oVars = GetObjectByTag(HS_VARS_OBJ);
     int nHitDie = GetHitDice(oMaster) - GetLocalInt(oVars, HS_VAR_LVL_LAG);
     int nCost = GetLocalInt(oVars, HS_VAR_CST_LVL);
     int bCanLevel = FALSE;
     if (nCost <= 0)
       { bCanLevel = TRUE; }
     else
       {
        int nHireCost = nCost * nHitDie;
        if (GetGold(oMaster) >= nHireCost)
          {
           bCanLevel = TRUE;
           TakeGoldFromCreature(nHireCost, oMaster, TRUE);
          }
       }
     if (bCanLevel)
       {
        SetAssociateState(NW_ASC_IS_BUSY);
        HenchLevelUp();
        DelayCommand(1.0, HenchEquipAppropriateWeapons(OBJECT_SELF, -5., FALSE));
        DelayCommand(3.0, SetAssociateState(NW_ASC_IS_BUSY, FALSE));
       }
    }

  // If another valid henchman, run the script for them too.
  object oHench = GetHenchman();
  if (GetIsObjectValid(oHench)) { ExecuteScript("hark_onply_lvlup", oHench); }
}
//::////////////////////////////////////////////////////////////////////////////
