diff options
Diffstat (limited to 'src/utils/chatutils.cpp')
-rw-r--r-- | src/utils/chatutils.cpp | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/src/utils/chatutils.cpp b/src/utils/chatutils.cpp index 09c2c69fb..41fcaa77b 100644 --- a/src/utils/chatutils.cpp +++ b/src/utils/chatutils.cpp @@ -20,8 +20,10 @@ #include "utils/chatutils.h" +#include "actormanager.h" #include "guild.h" #include "guildmanager.h" +#include "party.h" #include "being/localplayer.h" @@ -90,3 +92,78 @@ void outStringNormal(ChatTab *const tab, break; } } + +void replaceVars(std::string &str) +{ + if (!localPlayer || !actorManager) + return; + + if (str.find("<PLAYER>") != std::string::npos) + { + const Being *target = localPlayer->getTarget(); + if (!target || target->getType() != ActorType::PLAYER) + { + target = actorManager->findNearestLivingBeing( + localPlayer, 20, ActorType::PLAYER, true); + } + if (target) + replaceAll(str, "<PLAYER>", target->getName()); + else + replaceAll(str, "<PLAYER>", ""); + } + if (str.find("<MONSTER>") != std::string::npos) + { + const Being *target = localPlayer->getTarget(); + if (!target || target->getType() != ActorType::MONSTER) + { + target = actorManager->findNearestLivingBeing( + localPlayer, 20, ActorType::MONSTER, true); + } + if (target) + replaceAll(str, "<MONSTER>", target->getName()); + else + replaceAll(str, "<MONSTER>", ""); + } + if (str.find("<PEOPLE>") != std::string::npos) + { + StringVect names; + std::string newStr; + actorManager->getPlayerNames(names, false); + FOR_EACH (StringVectCIter, it, names) + { + if (*it != localPlayer->getName()) + newStr.append(*it).append(","); + } + if (newStr[newStr.size() - 1] == ',') + newStr = newStr.substr(0, newStr.size() - 1); + if (!newStr.empty()) + replaceAll(str, "<PEOPLE>", newStr); + else + replaceAll(str, "<PEOPLE>", ""); + } + if (str.find("<PARTY>") != std::string::npos) + { + StringVect names; + std::string newStr; + const Party *party = nullptr; + if (localPlayer->isInParty() && (party = localPlayer->getParty())) + { + party->getNames(names); + FOR_EACH (StringVectCIter, it, names) + { + if (*it != localPlayer->getName()) + newStr.append(*it).append(","); + } + if (newStr[newStr.size() - 1] == ',') + newStr = newStr.substr(0, newStr.size() - 1); + if (!newStr.empty()) + replaceAll(str, "<PARTY>", newStr); + else + replaceAll(str, "<PARTY>", ""); + } + else + { + replaceAll(str, "<PARTY>", ""); + } + } +} |