#include <lib.h>
#include "../customdefs.h"

inherit LIB_SENTIENT;
int wait = 0;
int tellOnce = 0;

static void create(){
    sentient::create();
    SetKeyName("Melchior");
    SetId( ({"imp","pet"}) );
    SetShort("Melchior");
    SetLong("This is Loki's pet imp Melchior.");
    SetLevel(99);
    SetRace("demon");
    SetClass("fighter");
    SetGender("male");
   /*SetInventory(([
                MY_ARMOR "/chainmail.c" : "wear chainmail",
                MY_ARMOR "/leather_boot_r.c" : "wear boot",
                MY_ARMOR "/leather_boot_l.c" : "wear boot",
                MY_WEAP "/sword.c" : "wield sword",
                ]));*/
    SetStat("strength",99);
    SetProperty("threshold", 100);
    set_heart_beat(1);
}

void init(){
    ::init();
}

void heart_beat(){
    if( file_name( environment( find_player( "loki" ) ) ) == "/realms/loki/workroom" ){
        wait = 1;
        if( !tellOnce ){
            tell_object( find_player( "loki" ), "%^RED%^Mental link: Master, I shall wait outside for you.%^RESET%^" );
        }
        tellOnce = 1;
    } else {
        wait = 0;
        tellOnce = 0;
    }
    if( environment( this_object() ) != environment( find_player( "loki" ) ) && !wait ){
        this_object()->eventMove( environment( find_player( "loki" ) ) );
        tell_room( file_name( environment( this_object() ) ), this_object()->GetKeyName()+" walks in." );
    }
    if( find_player( "loki" )->GetHealthPoints() != find_player( "loki" )->GetMaxHealthPoints() ){
        find_player( "loki" )->eventHeal( find_player( "loki" )->GetMaxHealthPoints() );
    }
    if( this_object()->GetHealthPoints() != this_object()->GetMaxHealthPoints() ){
        this_object()->eventHeal( this_object()->GetMaxHealthPoints() );
    }
    
}