#CLASS gmcp kill
#CLASS gmcp open


#FORMAT IAC  %a 255
#FORMAT DONT %a 254
#FORMAT DO   %a 253
#FORMAT WONT %a 252
#FORMAT WILL %a 251
#FORMAT SB   %a 250
#FORMAT SE   %a 240

#FORMAT GMCP %a 201

#ALIAS {debug {on|off}}
{
    #IF {"%1" == "on"} { 
        #VARIABLE {debug} {1}; 
        #SHOWME {@debug_log{Debug is <139>on<099>.}};
    };
    #ELSE { 
        #VARIABLE {debug} {0};
        #SHOWME {@debug_log{Debug is <139>off<099>.}};
    };
    #NOP;
}

#EVENT {IAC SB GMCP char.vitals IAC SE}
{
    #IF {"$debug" == "1"} {
        #SHOWME {@debug_log{%1}};
    };
    #VAR GMCP[oldvitals] {$GMCP[vitals]};
    #VAR GMCP[vitals] {%0};

    #math {hploss} {$GMCP[vitals][hp] - $GMCP[oldvitals][hp]};
    #if {$hploss < -150} {
        #format {hp_loss_display} {<139>HP IS FALLING! CAREFUL! (Lost %s HP)<099>} {$hploss};

        #if {&GMCP[oldvitals][hp]} {
            #echo {$hp_loss_display};
            #showme {\a};
        };
    };

    #math {xpgain} {$GMCP[vitals][xp] - $GMCP[oldvitals][xp]};
    #if {$xpgain > 5000} {
        #format {xp_gain_display} {(+<169>%g<099>xp)} {$xpgain};
        #delay {1} {#showme {$xp_gain_display};};
    };
    
    update_prompt;
}

#EVENT {IAC SB GMCP char.info IAC SE}
{
    #IF {"$debug" == "1"} {
        #SHOWME {@debug_log{%1}};
    };

    #nop We've SU'd, cleanup as appropriate;

    #nop delete group shields data;
    #variable {group_shields} {};
    #variable {group_shields_current} {};
    /writegroupshieldstofile;

    #nop xpreset - do we still want to? if we dont mis-calculate on SU continued tracking is nice;

    #nop store data about new character;
    #var GMCP[charinfo] {%0};

    #nop invalidate stale info;
    #unvar {GMCP[oldvitals]};
    #unvar {GMCP[vitals]};
    #var {latest_xp} {0};

    #nop reset prompt details;
    #var {tpa_status} {0};
    #var {tpa_color} {0};
    #nop #var {tpa_start} {0};
    #unvar {tpa_start};
    #unvar {quota};

    #nop re-split the screen to wipe out the prompt from last character;
    #split {3};
}

#EVENT {IAC SB GMCP room.info IAC SE}
{
    #IF {"$debug" == "1"} {
        #SHOWME {@debug_log{%1}};
    };
    #VAR GMCP[room][info] {%0};

    /spottimercheckroomid $GMCP[room][info][identifier];
}

#EVENT {IAC SB GMCP room.map IAC SE}
{
    #IF {"$debug" == "1"} {
        #SHOWME {@debug_log{%1}};
    };
    #VAR {minimap} {%0};
    #REPLACE {minimap} {u001b} {};
    #SYSTEM {rm logs/minimap.log && touch logs/minimap.log};

    #LINE {log} {logs/minimap.log} {$minimap};
    #SYSTEM {sed -i -e 's/^/     /' logs/minimap.log};
}

#EVENT {IAC SB GMCP room.writtenmap IAC SE}
{
    #IF {"$debug" == "1"} {
        #SHOWME {@debug_log{%1}};
    };
    #VAR GMCP[room][mdt] {%0};
    #REPLACE {GMCP[room][mdt]} {\\n} {};
    #SYSTEM {rm logs/mapdoortext.log && touch logs/mapdoortext.log};
    #LINE {log} {logs/mapdoortext.log} {$GMCP[room][mdt]};

    /personal.gmcp.writtenmap $GMCP[room][info][identifier];
}

#EVENT {IAC WILL GMCP}
{
    #SEND {$IAC$DO$GMCP\};
    #SEND {$IAC$SB$GMCP core.hello { "client" : "TinTin++", "version" : "2.02.60" } $IAC$SE\};
    #SEND {$IAC$SB$GMCP core.supports.set [ "char.login", "char.info", "char.vitals", "room.info", "room.map", "room.writtenmap" ] $IAC$SE\};
    #nop;
}

#EVENT {PROGRAM START}
{
    #VARIABLE CLIENT_NAME %0;
    #VARIABLE CLIENT_VERSION %1;
}

#FUNCTION {debug_log} {
    #format {result} {<<fac><<caf>GMCP<fac>><099>> %0};
};

#CLASS gmcp close
