From 973e203ed0ec6d4c14490351c8252c834291c067 Mon Sep 17 00:00:00 2001 From: AnnieRuru Date: Sat, 2 Mar 2019 05:52:40 +0800 Subject: [PATCH] Add constants and MERCINFO_GID to *getmercinfo script command --- doc/script_commands.txt | 23 +++++++------- src/map/script.c | 67 +++++++++++++++++++++++------------------ src/map/script.h | 17 +++++++++++ 3 files changed, 66 insertions(+), 41 deletions(-) diff --git a/doc/script_commands.txt b/doc/script_commands.txt index c3cc8a79905..e5c91e216aa 100644 --- a/doc/script_commands.txt +++ b/doc/script_commands.txt @@ -9836,17 +9836,18 @@ If char id is given, the information of that character is retrieved instead. Type specifies what information to retrieve and can be one of the following: - 0 - Database ID - 1 - Class - 2 - Name - 3 - Faith value for this mercenary's guild, if any - 4 - Calls value for this mercenary's guild, if any - 5 - Kill count - 6 - Remaining life time in msec - 7 - Level - -If the character does not have a mercenary, the command returns "" -for name and 0 for all other types. + MERCINFO_ID - Mercenary Database ID + MERCINFO_CLASS - Mercenary Class + MERCINFO_NAME - Mercenary Name + MERCINFO_FAITH - Mercenary faith value for this mercenary's guild, if any + MERCINFO_CALLS - Mercenary calls value for this mercenary's guild, if any + MERCINFO_KILLCOUNT - Mercenary kill count + MERCINFO_LIFETIME - Mercenary remaining life time in mili-second + MERCINFO_LEVEL - Mercenary Level + MERCINFO_GID - Mercenary Game ID + +If the character does not have a mercenary, the command returns "" for name +and 0 for all other types. --------------------------------------- //===================================== diff --git a/src/map/script.c b/src/map/script.c index 7e6e06376bb..11a4dd3336f 100644 --- a/src/map/script.c +++ b/src/map/script.c @@ -15617,16 +15617,9 @@ static BUILDIN(gethominfo) /// getmercinfo [,]; static BUILDIN(getmercinfo) { - int type; - struct map_session_data* sd; - struct mercenary_data* md; - - type = script_getnum(st,2); - - if (script_hasdata(st,3)) { - int char_id = script_getnum(st,3); - - if ((sd = script->charid2sd(st, char_id)) == NULL) { + struct map_session_data *sd; + if (script_hasdata(st, 3)) { + if ((sd = script->charid2sd(st, script_getnum(st, 3))) == NULL) { script_pushnil(st); return true; } @@ -15635,27 +15628,30 @@ static BUILDIN(getmercinfo) return true; } - md = ( sd->status.mer_id && sd->md ) ? sd->md : NULL; + struct mercenary_data *md = (sd->status.mer_id && sd->md)? sd->md : NULL; + int type = script_getnum(st, 2); + if (md == NULL) { + if (type == MERCINFO_NAME) + script_pushconststr(st, ""); + else + script_pushint(st, 0); + return true; + } - switch( type ) - { - case 0: script_pushint(st,md ? md->mercenary.mercenary_id : 0); break; - case 1: script_pushint(st,md ? md->mercenary.class_ : 0); break; - case 2: - if( md ) - script_pushstrcopy(st,md->db->name); - else - script_pushconststr(st,""); - break; - case 3: script_pushint(st,md ? mercenary->get_faith(md) : 0); break; - case 4: script_pushint(st,md ? mercenary->get_calls(md) : 0); break; - case 5: script_pushint(st,md ? md->mercenary.kill_count : 0); break; - case 6: script_pushint(st,md ? mercenary->get_lifetime(md) : 0); break; - case 7: script_pushint(st,md ? md->db->lv : 0); break; - default: - ShowError("buildin_getmercinfo: Invalid type %d (char_id=%d).\n", type, sd->status.char_id); - script_pushnil(st); - return false; + switch (type) { + case MERCINFO_ID: script_pushint(st, md->mercenary.mercenary_id); break; + case MERCINFO_CLASS: script_pushint(st, md->mercenary.class_); break; + case MERCINFO_NAME: script_pushstrcopy(st, md->db->name); break; + case MERCINFO_FAITH: script_pushint(st, mercenary->get_faith(md)); break; + case MERCINFO_CALLS: script_pushint(st, mercenary->get_calls(md)); break; + case MERCINFO_KILLCOUNT: script_pushint(st, md->mercenary.kill_count); break; + case MERCINFO_LIFETIME: script_pushint(st, mercenary->get_lifetime(md)); break; + case MERCINFO_LEVEL: script_pushint(st, md->db->lv); break; + case MERCINFO_GID: script_pushint(st, md->bl.id); break; + default: + ShowError("buildin_getmercinfo: Invalid type %d (char_id=%d).\n", type, sd->status.char_id); + script_pushnil(st); + return false; } return true; @@ -26116,6 +26112,17 @@ static void script_hardcoded_constants(void) script->set_constant("ITEMINFO_VIEWSPRITE", ITEMINFO_VIEWSPRITE, false, false); script->set_constant("ITEMINFO_TRADE", ITEMINFO_TRADE, false, false); + script->constdb_comment("getmercinfo options"); + script->set_constant("MERCINFO_ID,", MERCINFO_ID, false, false); + script->set_constant("MERCINFO_CLASS", MERCINFO_CLASS, false, false); + script->set_constant("MERCINFO_NAME", MERCINFO_NAME, false, false); + script->set_constant("MERCINFO_FAITH", MERCINFO_FAITH, false, false); + script->set_constant("MERCINFO_CALLS", MERCINFO_CALLS, false, false); + script->set_constant("MERCINFO_KILLCOUNT", MERCINFO_KILLCOUNT, false, false); + script->set_constant("MERCINFO_LIFETIME", MERCINFO_LIFETIME, false, false); + script->set_constant("MERCINFO_LEVEL", MERCINFO_LEVEL, false, false); + script->set_constant("MERCINFO_GID", MERCINFO_GID, false, false); + script->constdb_comment("monster skill states"); script->set_constant("MSS_ANY", MSS_ANY, false, false); script->set_constant("MSS_IDLE", MSS_IDLE, false, false); diff --git a/src/map/script.h b/src/map/script.h index 549ad32841f..54c5aad2a7d 100644 --- a/src/map/script.h +++ b/src/map/script.h @@ -460,6 +460,23 @@ enum script_iteminfo_types { ITEMINFO_MAX }; +/** + * Mercenary Info types. + */ +enum script_mercinfo_types { + MERCINFO_ID = 0, + MERCINFO_CLASS, + MERCINFO_NAME, + MERCINFO_FAITH, + MERCINFO_CALLS, + MERCINFO_KILLCOUNT, + MERCINFO_LIFETIME, + MERCINFO_LEVEL, + MERCINFO_GID, + + MERCINFO_MAX +}; + /** * Player blocking actions related flags. */