summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-12-27 17:56:43 +0300
committerAndrei Karas <akaras@inbox.ru>2013-12-27 17:56:43 +0300
commiteee2f72b047262cbb6478c67f2e5293a85ce79e4 (patch)
treea5924ee55bd5570825dccd0a344dd9f986157e12
parente068a57abf67381e4f58f90e40af3be6b386e240 (diff)
downloadmanaplus-eee2f72b047262cbb6478c67f2e5293a85ce79e4.tar.gz
manaplus-eee2f72b047262cbb6478c67f2e5293a85ce79e4.tar.bz2
manaplus-eee2f72b047262cbb6478c67f2e5293a85ce79e4.tar.xz
manaplus-eee2f72b047262cbb6478c67f2e5293a85ce79e4.zip
allow to owner talk from own pet.
New chat command: /talkpet text
-rw-r--r--src/commands.cpp9
-rw-r--r--src/commands.h3
-rw-r--r--src/gui/windows/chatwindow.cpp34
-rw-r--r--src/gui/windows/chatwindow.h2
-rw-r--r--src/net/chathandler.h3
-rw-r--r--src/net/ea/chathandler.cpp8
-rw-r--r--src/net/ea/chathandler.h3
7 files changed, 62 insertions, 0 deletions
diff --git a/src/commands.cpp b/src/commands.cpp
index 75347a9aa..8b25984b5 100644
--- a/src/commands.cpp
+++ b/src/commands.cpp
@@ -1252,6 +1252,15 @@ impHandler1(talkRaw)
Net::getChatHandler()->talkRaw(args);
}
+impHandler1(talkPet)
+{
+ // in future probably need add channel detection
+ if (player_node->getPet())
+ Net::getChatHandler()->talkPet(args, GENERAL_CHANNEL);
+ else
+ Net::getChatHandler()->talk(args, GENERAL_CHANNEL);
+}
+
impHandler0(testsdlfont)
{
#if defined USE_OPENGL && defined DEBUG_SDLFONT
diff --git a/src/commands.h b/src/commands.h
index 851789282..dca935226 100644
--- a/src/commands.h
+++ b/src/commands.h
@@ -127,6 +127,7 @@ namespace Commands
decHandler(testParticle);
decHandler(createItems);
decHandler(talkRaw);
+ decHandler(talkPet);
void replaceVars(std::string &str);
} // namespace Commands
@@ -221,6 +222,7 @@ enum
COMMAND_TEST_PARTICLE,
COMMAND_CREATEITEMS,
COMMAND_TALKRAW,
+ COMMAND_TALKPET,
COMMAND_HACK,
END_COMMANDS
};
@@ -315,6 +317,7 @@ static const CommandInfo commands[] =
{"testparticle", &Commands::testParticle, -1, true},
{"createitems", &Commands::createItems, -1, false},
{"talkraw", &Commands::talkRaw, -1, true},
+ {"talkpet", &Commands::talkPet, -1, true},
{"hack", &Commands::hack, -1, true}
};
diff --git a/src/gui/windows/chatwindow.cpp b/src/gui/windows/chatwindow.cpp
index d658ae183..44024b7f1 100644
--- a/src/gui/windows/chatwindow.cpp
+++ b/src/gui/windows/chatwindow.cpp
@@ -1482,6 +1482,20 @@ bool ChatWindow::resortChatLog(std::string line, Own own,
// ignore special message formats.
if (line.find(": \302\202\302") != std::string::npos)
return false;
+
+ // pet talk message detected
+ if (line.find(": \302\202\303 ") != std::string::npos)
+ {
+ if (actorManager && idx2 > 1)
+ {
+ const std::string nick = line.substr(0, idx2 - 1);
+ line = line.substr(idx2 + 6);
+ localPetSay(nick, line);
+ }
+
+ return false;
+ }
+
line = line.erase(idx + 2, 2);
tradeChatTab->chatLog(prefix + line, own, ignoreRecord,
tryRemoveColors);
@@ -1548,6 +1562,26 @@ void ChatWindow::battleChatLog(const std::string &line, Own own,
debugChatTab->chatLog(line, own, ignoreRecord, tryRemoveColors);
}
+void ChatWindow::localPetSay(const std::string &nick, const std::string &text)
+{
+ Being *const being = actorManager->findBeingByName(
+ nick, ActorSprite::PLAYER);
+ Being *pet = nullptr;
+ if (being)
+ {
+ pet = being->getPet();
+ if (pet)
+ pet->setSpeech(text, GENERAL_CHANNEL);
+ }
+
+ if (!localChatTab)
+ return;
+ if (pet)
+ localChatTab->chatLog(strprintf(_("%s's pet"), nick.c_str()), text);
+ else
+ localChatTab->chatLog(nick, text);
+}
+
void ChatWindow::initTradeFilter()
{
const std::string tradeListName = client->getServerConfigDirectory()
diff --git a/src/gui/windows/chatwindow.h b/src/gui/windows/chatwindow.h
index a1a7d77ee..8cda0fa84 100644
--- a/src/gui/windows/chatwindow.h
+++ b/src/gui/windows/chatwindow.h
@@ -292,6 +292,8 @@ class ChatWindow final : public Window,
void postInit() override final;
+ void localPetSay(const std::string &nick, const std::string &text);
+
#ifdef USE_PROFILER
void logicChildren();
#endif
diff --git a/src/net/chathandler.h b/src/net/chathandler.h
index aab74e85a..db866ac3b 100644
--- a/src/net/chathandler.h
+++ b/src/net/chathandler.h
@@ -39,6 +39,9 @@ class ChatHandler
virtual void talk(const std::string &restrict text,
const std::string &restrict channel) const = 0;
+ virtual void talkPet(const std::string &restrict text,
+ const std::string &restrict channel) const = 0;
+
virtual void talkRaw(const std::string &text) const = 0;
virtual void me(const std::string &restrict text,
diff --git a/src/net/ea/chathandler.cpp b/src/net/ea/chathandler.cpp
index 698a03ef4..2bfee7ad2 100644
--- a/src/net/ea/chathandler.cpp
+++ b/src/net/ea/chathandler.cpp
@@ -70,6 +70,14 @@ void ChatHandler::me(const std::string &restrict text,
talk(action, channel);
}
+void ChatHandler::talkPet(const std::string &restrict text,
+ const std::string &restrict channel) const
+{
+ // here need string duplication
+ std::string action = strprintf("\302\202\303 %s", text.c_str());
+ talk(action, channel);
+}
+
void ChatHandler::processWhisperResponse(Net::MessageIn &msg)
{
BLOCK_START("ChatHandler::processWhisperResponse")
diff --git a/src/net/ea/chathandler.h b/src/net/ea/chathandler.h
index cba709577..b2e38fede 100644
--- a/src/net/ea/chathandler.h
+++ b/src/net/ea/chathandler.h
@@ -38,6 +38,9 @@ class ChatHandler : public Net::ChatHandler
A_DELETE_COPY(ChatHandler)
+ void talkPet(const std::string &restrict text,
+ const std::string &restrict channel) const override final;
+
void me(const std::string &restrict text,
const std::string &restrict channel) const override final;