From e671f852e4bf2c7e6983db517d39c96b291d3e8b Mon Sep 17 00:00:00 2001 From: Kinglykrab Date: Tue, 6 Apr 2021 22:19:38 -0400 Subject: [PATCH 1/2] Add HTML color tag method to Perl and Lua. - Add quest::gethexcolorcode(color_name) to Perl. - Add eq.get_hex_color_code(color_name) to Lua. Full color list here: https://pastebin.com/rUYKr1ye --- zone/embparser_api.cpp | 18 +++ zone/lua_general.cpp | 5 + zone/questmgr.cpp | 324 ++++++++++++++++++++++++++++++++++++++++- zone/questmgr.h | 1 + 4 files changed, 347 insertions(+), 1 deletion(-) diff --git a/zone/embparser_api.cpp b/zone/embparser_api.cpp index 1ed0df3414..44692c041b 100644 --- a/zone/embparser_api.cpp +++ b/zone/embparser_api.cpp @@ -6472,6 +6472,23 @@ XS(XS__secondstotime) { XSRETURN(1); } +XS(XS__gethexcolorcode); +XS(XS__gethexcolorcode) { + dXSARGS; + if (items != 1) { + Perl_croak(aTHX_ "Usage: quest::gethexcolorcode(std::string color_name)"); + } + + dXSTARG; + std::string hex_color_code; + std::string color_name = SvPV_nolen(ST(0)); + hex_color_code = quest_manager.gethexcolorcode(color_name); + sv_setpv(TARG, hex_color_code.c_str()); + XSprePUSH; + PUSHTARG; + XSRETURN(1); +} + /* This is the callback perl will look for to setup the quest package's XSUBs @@ -6680,6 +6697,7 @@ EXTERN_C XS(boot_quest) { newXS(strcpy(buf, "forcedooropen"), XS__forcedooropen, file); newXS(strcpy(buf, "getcharidbyname"), XS__getcharidbyname, file); newXS(strcpy(buf, "getclassname"), XS__getclassname, file); + newXS(strcpy(buf, "gethexcolorcode"), XS__gethexcolorcode, file); newXS(strcpy(buf, "getcurrencyid"), XS__getcurrencyid, file); newXS(strcpy(buf, "get_expedition"), XS__get_expedition, file); newXS(strcpy(buf, "get_expedition_by_char_id"), XS__get_expedition_by_char_id, file); diff --git a/zone/lua_general.cpp b/zone/lua_general.cpp index 668028eb8f..a1b0a1a267 100644 --- a/zone/lua_general.cpp +++ b/zone/lua_general.cpp @@ -2322,6 +2322,10 @@ std::string lua_seconds_to_time(int duration) { return quest_manager.secondstotime(duration); } +std::string lua_get_hex_color_code(std::string color_name) { + return quest_manager.gethexcolorcode(color_name); +} + #define LuaCreateNPCParse(name, c_type, default_value) do { \ cur = table[#name]; \ if(luabind::type(cur) != LUA_TNIL) { \ @@ -2863,6 +2867,7 @@ luabind::scope lua_register_general() { luabind::def("debug", (void(*)(std::string, int))&lua_debug), luabind::def("log_combat", (void(*)(std::string))&lua_log_combat), luabind::def("seconds_to_time", &lua_seconds_to_time), + luabind::def("get_hex_color_code", &lua_get_hex_color_code), /** * Expansions diff --git a/zone/questmgr.cpp b/zone/questmgr.cpp index fc3e272394..849147d308 100644 --- a/zone/questmgr.cpp +++ b/zone/questmgr.cpp @@ -4285,4 +4285,326 @@ std::string QuestManager::secondstotime(int duration) { time_string = fmt::format("{} {}", seconds, second_string); } return time_string; -} \ No newline at end of file +} + +std::string QuestManager::gethexcolorcode(std::string color_name) { + const std::map colors = { + { "Black", "#000000" }, + { "Brown", "#804000" }, + { "Burgundy", "#800000" }, + { "Cadet Blue", "#77BFC7" }, + { "Cadet Blue1", "#4C787E" }, + { "Chartreuse", "#8AFB17" }, + { "Chartreuse1", "#7FE817" }, + { "Chartreuse2", "#6CC417" }, + { "Chartreuse3", "#437C17" }, + { "Chocolate", "#C85A17" }, + { "Coral", "#F76541" }, + { "Coral1", "#E55B3C" }, + { "Coral2", "#C34A2C" }, + { "Cornflower Blue", "#151B8D" }, + { "Cyan", "#00FFFF" }, + { "Cyan1", "#57FEFF" }, + { "Cyan2", "#50EBEC" }, + { "Cyan3", "#46C7C7" }, + { "Cyan4", "#307D7E" }, + { "Dark Blue", "#0000A0" }, + { "Dark Goldenrod", "#AF7817" }, + { "Dark Goldenrod1", "#FBB117" }, + { "Dark Goldenrod2", "#E8A317" }, + { "Dark Goldenrod3", "#C58917" }, + { "Dark Goldenrod4", "#7F5217" }, + { "Dark Green", "#254117" }, + { "Dark Grey", "#808080" }, + { "Dark Olive Green", "#CCFB5D" }, + { "Dark Olive Green2", "#BCE954" }, + { "Dark Olive Green3", "#A0C544" }, + { "Dark Olive Green4", "#667C26" }, + { "Dark Orange", "#F88017" }, + { "Dark Orange1", "#F87217" }, + { "Dark Orange2", "#E56717" }, + { "Dark Orange3", "#7E3117" }, + { "Dark Orange3", "#C35617" }, + { "Dark Orchid", "#7D1B7E" }, + { "Dark Orchid1", "#B041FF" }, + { "Dark Orchid2", "#A23BEC" }, + { "Dark Orchid3", "#8B31C7" }, + { "Dark Orchid4", "#571B7e" }, + { "Dark Purple", "#800080" }, + { "Dark Salmon", "#E18B6B" }, + { "Dark Sea Green", "#8BB381" }, + { "Dark Sea Green1", "#C3FDB8" }, + { "Dark Sea Green2", "#B5EAAA" }, + { "Dark Sea Green3", "#99C68E" }, + { "Dark Sea Green4", "#617C58" }, + { "Dark Slate Blue", "#2B3856" }, + { "Dark Slate Gray", "#25383C" }, + { "Dark Slate Gray1", "#9AFEFF" }, + { "Dark Slate Gray2", "#8EEBEC" }, + { "Dark Slate Gray3", "#78c7c7" }, + { "Dark Slate Gray4", "#4C7D7E" }, + { "Dark Turquoise", "#3B9C9C" }, + { "Dark Violet", "#842DCE" }, + { "Deep Pink", "#F52887" }, + { "Deep Pink1", "#E4287C" }, + { "Deep Pink2", "#C12267" }, + { "Deep Pink3", "#7D053F" }, + { "Deep Sky Blue", "#3BB9FF" }, + { "Deep Sky Blue1", "#38ACEC" }, + { "Deep Sky Blue2", "#3090C7" }, + { "Deep Sky Blue3", "#25587E" }, + { "Dim Gray", "#463E41" }, + { "Dodger Blue", "#1589FF" }, + { "Dodger Blue1", "#157DEC" }, + { "Dodger Blue2", "#1569C7" }, + { "Dodger Blue3", "#153E7E" }, + { "Firebrick", "#800517" }, + { "Firebrick1", "#F62817" }, + { "Firebrick2", "#E42217" }, + { "Firebrick3", "#C11B17" }, + { "Forest Green", "#4E9258" }, + { "Forest Green1", "#808000" }, + { "Gold", "#D4A017" }, + { "Gold1", "#FDD017" }, + { "Gold2", "#EAC117" }, + { "Gold3", "#C7A317" }, + { "Gold4", "#806517" }, + { "Goldenrod", "#EDDA74" }, + { "Goldenrod1", "#FBB917" }, + { "Goldenrod2", "#E9AB17" }, + { "Goldenrod3", "#C68E17" }, + { "Goldenrod4", "#805817" }, + { "Grass Green", "#408080" }, + { "Gray", "#736F6E" }, + { "Gray1", "#150517" }, + { "Gray2", "#250517" }, + { "Gray3", "#2B1B17" }, + { "Gray4", "#302217" }, + { "Gray5", "#302226" }, + { "Gray6", "#342826" }, + { "Gray7", "#34282C" }, + { "Gray8", "#382D2C" }, + { "Gray9", "#3b3131" }, + { "Gray10", "#3E3535" }, + { "Gray11", "#413839" }, + { "Gray12", "#41383C" }, + { "Gray13", "#463E3F" }, + { "Gray14", "#4A4344" }, + { "Gray15", "#4C4646" }, + { "Gray16", "#4E4848" }, + { "Gray17", "#504A4B" }, + { "Gray18", "#544E4F" }, + { "Gray19", "#565051" }, + { "Gray19", "#595454" }, + { "Gray20", "#5C5858" }, + { "Gray21", "#5F5A59" }, + { "Gray22", "#625D5D" }, + { "Gray23", "#646060" }, + { "Gray24", "#666362" }, + { "Gray25", "#696565" }, + { "Gray26", "#6D6968" }, + { "Gray27", "#6E6A6B" }, + { "Gray28", "#726E6D" }, + { "Gray29", "#747170" }, + { "Green", "#00FF00" }, + { "Green1", "#5FFB17" }, + { "Green2", "#59E817" }, + { "Green3", "#4CC417" }, + { "Green4", "#347C17" }, + { "Green Yellow", "#B1FB17" }, + { "Hot Pink", "#F660AB" }, + { "Hot Pink1", "#F665AB" }, + { "Hot Pink2", "#E45E9D" }, + { "Hot Pink3", "#C25283" }, + { "Hot Pink4", "#7D2252" }, + { "Indian Red", "#F75D59" }, + { "Indian Red2", "#E55451" }, + { "Indian Red3", "#C24641" }, + { "Indian Red4", "#7E2217" }, + { "Khaki", "#ADA96E" }, + { "Khaki1", "#FFF380" }, + { "Khaki2", "#EDE275" }, + { "Khaki3", "#C9BE62" }, + { "Khaki4", "#827839" }, + { "Lavender", "#E3E4FA" }, + { "Lavender Blush", "#FDEEF4" }, + { "Lavender Blush1", "#EBDDE2" }, + { "Lavender Blush2", "#C8BBBE" }, + { "Lavender Blush3", "#817679" }, + { "Lawn Green", "#87F717" }, + { "Lemon Chiffon", "#FFF8C6" }, + { "Lemon Chiffon1", "#ECE5B6" }, + { "Lemon Chiffon2", "#C9C299" }, + { "Lemon Chiffon3", "#827B60" }, + { "Light Blue", "#0000FF" }, + { "Light Blue1", "#ADDFFF" }, + { "Light Blue2", "#BDEDFF" }, + { "Light Blue3", "#AFDCEC" }, + { "Light Blue4", "#95B9C7" }, + { "Light Blue5", "#5E767E" }, + { "Light Coral", "#E77471" }, + { "Light Cyan", "#E0FFFF" }, + { "Light Cyan1", "#CFECEC" }, + { "Light Cyan2", "#AFC7C7" }, + { "Light Cyan3", "#717D7D" }, + { "Light Golden", "#ECD672" }, + { "Light Goldenrod", "#ECD872" }, + { "Light Goldenrod1", "#FFE87C" }, + { "Light Goldenrod2", "#C8B560" }, + { "Light Goldenrod3", "#817339" }, + { "Light Goldenrod Yellow", "#FAF8CC" }, + { "Light Grey", "#C0C0C0" }, + { "Light Pink", "#FAAFBA" }, + { "Light Pink1", "#F9A7B0" }, + { "Light Pink2", "#E799A3" }, + { "Light Pink3", "#C48189" }, + { "Light Pink4", "#7F4E52" }, + { "Light Purple", "#FF0080" }, + { "Light Salmon", "#F9966B" }, + { "Light Salmon1", "#E78A61" }, + { "Light Salmon2", "#C47451" }, + { "Light Salmon3", "#7F462C" }, + { "Light Sea Green", "#3EA99F" }, + { "Light Sky Blue", "#82CAFA" }, + { "Light Sky Blue1", "#A0CFEC" }, + { "Light Sky Blue2", "#87AFC7" }, + { "Light Sky Blue3", "#566D7E" }, + { "Light Slate Blue", "#736AFF" }, + { "Light Slate Gray", "#6D7B8D" }, + { "Light Steel Blue", "#728FCE" }, + { "Light Steel Blue1", "#C6DEFF" }, + { "Light Steel Blue2", "#B7CEEC" }, + { "Light Steel Blue3", "#646D7E" }, + { "Lime Green", "#41A317" }, + { "Magenta", "#FF00FF" }, + { "Magenta1", "#F433FF" }, + { "Magenta2", "#E238EC" }, + { "Magenta3", "#C031C7" }, + { "Maroon", "#810541" }, + { "Maroon1", "#F535AA" }, + { "Maroon2", "#E3319D" }, + { "Maroon3", "#C12283" }, + { "Maroon4", "#7D0552" }, + { "Medium Aquamarine", "#348781" }, + { "Medium Forest Green", "#347235" }, + { "Medium Orchid", "#B048B5" }, + { "Medium Orchid1", "#D462FF" }, + { "Medium Orchid2", "#C45AEC" }, + { "Medium Orchid3", "#A74AC7" }, + { "Medium Orchid4", "#6A287E" }, + { "Medium Purple", "#8467D7" }, + { "Medium Purple1", "#9E7BFF" }, + { "Medium Purple2", "#9172EC" }, + { "Medium Purple3", "#7A5DC7" }, + { "Medium Purple4", "#4E387E" }, + { "Medium Sea Green", "#306754" }, + { "Medium Slate Blue", "#5E5A80" }, + { "Medium Spring Green", "#348017" }, + { "Medium Turquoise", "#48CCCD" }, + { "Medium Violet Red", "#CA226B" }, + { "Midnight Blue", "#151B54" }, + { "Orange", "#FF8040" }, + { "Pale Turquoise", "#92C7C7" }, + { "Pale Turquoise1", "#5E7D7E" }, + { "Pale Violet Red", "#D16587" }, + { "Pale Violet Red1", "#F778A1" }, + { "Pale Violet Red2", "#E56E94" }, + { "Pale Violet Red3", "#C25A7C" }, + { "Pale Violet Red4", "#7E354D" }, + { "Pastel Green", "#00FF00" }, + { "Pink", "#FAAFBE" }, + { "Pink1", "#FF00FF" }, + { "Pink2", "#E7A1B0" }, + { "Pink3", "#C48793" }, + { "Pink4", "#7F525D" }, + { "Plum", "#B93B8F" }, + { "Plum1", "#F9B7FF" }, + { "Plum2", "#E6A9EC" }, + { "Plum3", "#C38EC7" }, + { "Plum4", "#7E587E" }, + { "Purple", "#8E35EF" }, + { "Purple1", "#893BFF" }, + { "Purple2", "#7F38EC" }, + { "Purple3", "#6C2DC7" }, + { "Purple4", "#461B7E" }, + { "Red", "#FF0000" }, + { "Red1", "#F62217" }, + { "Red2", "#E41B17" }, + { "Rosy Brown", "#B38481" }, + { "Rosy Brown1", "#FBBBB9" }, + { "Rosy Brown2", "#E8ADAA" }, + { "Rosy Brown3", "#C5908E" }, + { "Rosy Brown4", "#7F5A58" }, + { "Royal Blue", "#2B60DE" }, + { "Royal Blue1", "#306EFF" }, + { "Royal Blue2", "#2B65EC" }, + { "Royal Blue3", "#2554C7" }, + { "Royal Blue4", "#15317E" }, + { "Salmon1", "#F88158" }, + { "Salmon2", "#E67451" }, + { "Salmon3", "#C36241" }, + { "Salmon4", "#7E3817" }, + { "Sandy Brown", "#EE9A4D" }, + { "Sea Green", "#4E8975" }, + { "Sea Green1", "#6AFB92" }, + { "Sea Green2", "#64E986" }, + { "Sea Green3", "#54C571" }, + { "Sea Green4", "#387C44" }, + { "Sienna", "#8A4117" }, + { "Sienna1", "#F87431" }, + { "Sienna2", "#E66C2C" }, + { "Sienna3", "#C35817" }, + { "Sienna4", "#7E3517" }, + { "Sky Blue", "#82CAFF" }, + { "Sky Blue1", "#6698FF" }, + { "Sky Blue2", "#79BAEC" }, + { "Sky Blue3", "#659EC7" }, + { "Sky Blue4", "#41627E" }, + { "Slate Blue", "#357EC7" }, + { "Slate Blue1", "#737CA1" }, + { "Slate Blue2", "#6960EC" }, + { "Slate Blue3", "#342D7E" }, + { "Slate Gray", "#657383" }, + { "Slate Gray1", "#C2DFFF" }, + { "Slate Gray2", "#B4CFEC" }, + { "Slate Gray3", "#98AFC7" }, + { "Slate Gray4", "#616D7E" }, + { "Spring Green", "#4AA02C" }, + { "Spring Green1", "#5EFB6E" }, + { "Spring Green2", "#57E964" }, + { "Spring Green3", "#4CC552" }, + { "Spring Green4", "#347C2C" }, + { "Steel Blue", "#4863A0" }, + { "Steel Blue1", "#5CB3FF" }, + { "Steel Blue2", "#56A5EC" }, + { "Steel Blue3", "#488AC7" }, + { "Steel Blue4", "#2B547E" }, + { "Thistle", "#D2B9D3" }, + { "Thistle1", "#FCDFFF" }, + { "Thistle2", "#E9CFEC" }, + { "Thistle3", "#C6AEC7" }, + { "Thistle4", "#806D7E" }, + { "Turquoise", "#00FFFF" }, + { "Turquoise1", "#43C6DB" }, + { "Turquoise2", "#52F3FF" }, + { "Turquoise3", "#4EE2EC" }, + { "Turquoise4", "#43BFC7" }, + { "Violet", "#8D38C9" }, + { "Violet Red", "#F6358A" }, + { "Violet Red1", "#F6358A" }, + { "Violet Red2", "#E4317F" }, + { "Violet Red3", "#C12869" }, + { "Violet Red4", "#7D0541" }, + { "White", "#FFFFFF" }, + { "Yellow", "#FFFF00" }, + { "Yellow1", "#FFFC17" }, + { "Yellow Green", "#52D017" } + }; + for (auto color : colors) { + if (!strcmp(str_tolower(color.first).c_str(), str_tolower(color_name).c_str())) { + return color.second; + } + } + + return std::string(); +} diff --git a/zone/questmgr.h b/zone/questmgr.h index 0bb765fedb..9b90325df7 100644 --- a/zone/questmgr.h +++ b/zone/questmgr.h @@ -372,6 +372,7 @@ class QuestManager { void ClearNPCTypeCache(int npctype_id); void ReloadZoneStaticData(); std::string secondstotime(int duration); + std::string gethexcolorcode(std::string color_name); Client *GetInitiator() const; NPC *GetNPC() const; From e442a6be2839bbde97b65582014f80b87ecc8a68 Mon Sep 17 00:00:00 2001 From: Alex Date: Sat, 17 Apr 2021 14:27:47 -0400 Subject: [PATCH 2/2] Convert to static and use strcasecmp over strcmp. --- zone/questmgr.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/zone/questmgr.cpp b/zone/questmgr.cpp index 849147d308..2c95f366bf 100644 --- a/zone/questmgr.cpp +++ b/zone/questmgr.cpp @@ -4288,7 +4288,7 @@ std::string QuestManager::secondstotime(int duration) { } std::string QuestManager::gethexcolorcode(std::string color_name) { - const std::map colors = { + static const std::map colors = { { "Black", "#000000" }, { "Brown", "#804000" }, { "Burgundy", "#800000" }, @@ -4601,7 +4601,7 @@ std::string QuestManager::gethexcolorcode(std::string color_name) { { "Yellow Green", "#52D017" } }; for (auto color : colors) { - if (!strcmp(str_tolower(color.first).c_str(), str_tolower(color_name).c_str())) { + if (!strcasecmp(color.first.c_str(), color_name.c_str())) { return color.second; } }