From 4a4d6bd39b88933f5db4b632b28e1444062ad25a Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 8 Dec 2011 21:50:36 +0300 Subject: Add variables for any chat text/commands. - target or nearest player nick. - target or nearest monster name. - comma separated list of visible players (except self). - all party members (except self). Example usage: type in chat: hello . --- src/commandhandler.cpp | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) (limited to 'src/commandhandler.cpp') diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp index d04fda150..862ac56b4 100644 --- a/src/commandhandler.cpp +++ b/src/commandhandler.cpp @@ -32,6 +32,7 @@ #include "localplayer.h" #include "logger.h" #include "main.h" +#include "party.h" #include "gui/chatwindow.h" #include "gui/helpwindow.h" @@ -1194,3 +1195,82 @@ void CommandHandler::handleDump(const std::string &args A_UNUSED, { } #endif + +void CommandHandler::replaceVars(std::string &str) +{ + if (!player_node || !actorSpriteManager) + return; + + if (str.find("") != std::string::npos) + { + Being *target = player_node->getTarget(); + if (!target || target->getType() != ActorSprite::PLAYER) + { + target = actorSpriteManager->findNearestLivingBeing( + player_node, 20, ActorSprite::PLAYER); + } + if (target) + replaceAll(str, "", target->getName()); + else + replaceAll(str, "", ""); + } + if (str.find("") != std::string::npos) + { + Being *target = player_node->getTarget(); + if (!target || target->getType() != ActorSprite::MONSTER) + { + target = actorSpriteManager->findNearestLivingBeing( + player_node, 20, ActorSprite::MONSTER); + } + if (target) + replaceAll(str, "", target->getName()); + else + replaceAll(str, "", ""); + } + if (str.find("") != std::string::npos) + { + std::vector names; + std::string newStr = ""; + actorSpriteManager->getPlayerNames(names, false); + std::vector::const_iterator it = names.begin(); + std::vector::const_iterator it_end = names.end(); + for (; it != it_end; ++ it) + { + if (*it != player_node->getName()) + newStr += *it + ","; + } + if (newStr[newStr.size() - 1] == ',') + newStr = newStr.substr(0, newStr.size() - 1); + if (!newStr.empty()) + replaceAll(str, "", newStr); + else + replaceAll(str, "", ""); + } + if (str.find("") != std::string::npos) + { + std::vector names; + std::string newStr = ""; + Party *party = nullptr; + if (player_node->isInParty() && (party = player_node->getParty())) + { + party->getNames(names); + std::vector::const_iterator it = names.begin(); + std::vector::const_iterator it_end = names.end(); + for (; it != it_end; ++ it) + { + if (*it != player_node->getName()) + newStr += *it + ","; + } + if (newStr[newStr.size() - 1] == ',') + newStr = newStr.substr(0, newStr.size() - 1); + if (!newStr.empty()) + replaceAll(str, "", newStr); + else + replaceAll(str, "", ""); + } + else + { + replaceAll(str, "", ""); + } + } +} -- cgit v1.2.3-60-g2f50