diff --git a/HeavenClient/Gameplay/MapleMap/MapChars.cpp b/HeavenClient/Gameplay/MapleMap/MapChars.cpp index 1e409dc96..85a0685cd 100644 --- a/HeavenClient/Gameplay/MapleMap/MapChars.cpp +++ b/HeavenClient/Gameplay/MapleMap/MapChars.cpp @@ -17,6 +17,9 @@ ////////////////////////////////////////////////////////////////////////////////// #include "MapChars.h" +#include +#include + namespace ms { void MapChars::draw(Layer::Id layer, double viewx, double viewy, float alpha) const @@ -95,6 +98,21 @@ namespace ms } } + int32_t MapChars::find(const std::string &name) const + { + auto same = [](unsigned char a, unsigned char b) { return std::tolower(a) == std::tolower(b); }; + + for (auto &[oid, object] : chars) + { + std::string other = static_cast(*object).get_name(); + + if (other.size() == name.size() && std::equal(other.begin(), other.end(), name.begin(), same)) + return oid; + } + + return 0; + } + std::vector MapChars::ring_wearers(RingKind kind) const { std::vector wearers; diff --git a/HeavenClient/Gameplay/MapleMap/MapChars.h b/HeavenClient/Gameplay/MapleMap/MapChars.h index e051aeb7e..7a207f0a7 100644 --- a/HeavenClient/Gameplay/MapleMap/MapChars.h +++ b/HeavenClient/Gameplay/MapleMap/MapChars.h @@ -74,6 +74,9 @@ namespace ms Optional get_char(int32_t cid); + // The id of the character on the map with a name, ignoring case, or 0. + int32_t find(const std::string &name) const; + // Draw HP bars over the heads of the player's party members. void draw_party_hp(const Party &party, int32_t self, int32_t mapid, double viewx, double viewy, float alpha) const; diff --git a/HeavenClient/IO/UITypes/UIChatBar.cpp b/HeavenClient/IO/UITypes/UIChatBar.cpp index 0161ca41b..f5f379eec 100644 --- a/HeavenClient/IO/UITypes/UIChatBar.cpp +++ b/HeavenClient/IO/UITypes/UIChatBar.cpp @@ -22,6 +22,7 @@ #include #include "UIGroupPicker.h" +#include "UITradingRoom.h" #include "UINotice.h" #include "UIWhisperPrompt.h" #include "UIStatusBar.h" @@ -390,6 +391,14 @@ namespace ms { send_whisper(target, ""); } + // A trade with someone on the map, as from their + // character info (FUN_0052fad4). v83's /CashTrade asks + // for a cash trade, which RustMS doesn't have. + else if (parse_command_argument(msg, "/trade", target) + || parse_command_argument(msg, "/Game Trade", target)) + { + UITradingRoom::request(Stage::get().get_chars().find(target)); + } else if (PartyCommands::run(msg)) { } diff --git a/HeavenClient/IO/UITypes/UITradingRoom.cpp b/HeavenClient/IO/UITypes/UITradingRoom.cpp index a6d541d6b..2c8bef56a 100644 --- a/HeavenClient/IO/UITypes/UITradingRoom.cpp +++ b/HeavenClient/IO/UITypes/UITradingRoom.cpp @@ -410,11 +410,11 @@ namespace ms const char *refusal = nullptr; - // Nor while a dialog is open, nor from a GM's account. - if (UI::get().dialog_open()) - refusal = "Not available"; - else if (Configuration::get().get_grade().gm()) + // Nor from a GM's account, nor while a dialog is open. + if (Configuration::get().get_grade().gm()) refusal = account_grade::NOT_FOR_ADMIN; + else if (UI::get().dialog_open()) + refusal = "Not available"; else if (Stage::get().is_player(cid) || !Stage::get().get_character(cid)) refusal = "Unable to find the character.";