rework speak types

master
Eduardo Bart 12 years ago
parent fa915e088c
commit 05f649cdeb

@ -298,3 +298,18 @@ KeyCodeDescs = {
[KeyNumpad8] = 'Numpad8',
[KeyNumpad9] = 'Numpad9'
}
SpeakSay = 1
SpeakWhisper = 2
SpeakYell = 3
SpeakBroadcast = 4
SpeakPrivate = 5
SpeakPrivateRed = 6
SpeakPrivatePlayerToNpc = 7
SpeakPrivateNpcToPlayer = 8
SpeakChannelYellow = 9
SpeakChannelWhite = 10
SpeakChannelRed = 11
SpeakChannelOrange = 12
SpeakMonsterSay = 13
SpeakMonsterYell = 14

@ -31,5 +31,3 @@ int main(int argc, const char* argv[])
app.terminate();
return 0;
}
// for freenode: fk39HHDJJF

@ -264,6 +264,23 @@ namespace Otc
IconPzBlock = 8192,
IconPz = 16384
};
enum SpeakType {
SpeakSay = 1,
SpeakWhisper,
SpeakYell,
SpeakBroadcast,
SpeakPrivate,
SpeakPrivateRed,
SpeakPrivatePlayerToNpc,
SpeakPrivateNpcToPlayer,
SpeakChannelYellow,
SpeakChannelWhite,
SpeakChannelRed,
SpeakChannelOrange,
SpeakMonsterSay,
SpeakMonsterYell
};
}
#endif

@ -172,9 +172,9 @@ void Game::processTextMessage(const std::string& type, const std::string& messag
g_lua.callGlobalField("Game","onTextMessage", type, message);
}
void Game::processCreatureSpeak(const std::string& name, int level, const std::string& type, const std::string& message, int channelId, const Position& creaturePos)
void Game::processCreatureSpeak(const std::string& name, int level, Otc::SpeakType type, const std::string& message, int channelId, const Position& creaturePos)
{
if(creaturePos.isValid() && (type == "say" || type == "whisper" || type == "yell" || type == "monsterSay" || type == "monsterYell")) {
if(creaturePos.isValid() && (type == Otc::SpeakSay || type == Otc::SpeakWhisper || type == Otc::SpeakYell || type == Otc::SpeakMonsterSay || type == Otc::SpeakMonsterYell)) {
StaticTextPtr staticText = StaticTextPtr(new StaticText);
staticText->addMessage(name, type, message);
g_map.addThing(staticText, creaturePos);
@ -461,24 +461,23 @@ int Game::getThingStackpos(const ThingPtr& thing)
void Game::talk(const std::string& message)
{
talkChannel("say", 0, message);
talkChannel(Otc::SpeakSay, 0, message);
}
void Game::talkChannel(const std::string& speakTypeDesc, int channelId, const std::string& message)
void Game::talkChannel(Otc::SpeakType speakType, int channelId, const std::string& message)
{
if(!isOnline() || !checkBotProtection())
return;
m_protocolGame->sendTalk(speakTypeDesc, channelId, "", message);
m_protocolGame->sendTalk(speakType, channelId, "", message);
}
void Game::talkPrivate(const std::string& speakTypeDesc, const std::string& receiver, const std::string& message)
void Game::talkPrivate(Otc::SpeakType speakType, const std::string& receiver, const std::string& message)
{
if(!isOnline() || !checkBotProtection())
return;
m_protocolGame->sendTalk(speakTypeDesc, 0, receiver, message);
m_protocolGame->sendTalk(speakType, 0, receiver, message);
}
void Game::openPrivateChannel(const std::string& receiver)
{
if(!isOnline() || !checkBotProtection())

@ -52,7 +52,7 @@ public:
double magicLevel, double magicLevelPercent,
double soul, double stamina);
void processTextMessage(const std::string& type, const std::string& message);
void processCreatureSpeak(const std::string& name, int level, const std::string& type, const std::string& message, int channelId, const Position& creaturePos);
void processCreatureSpeak(const std::string& name, int level, Otc::SpeakType type, const std::string& message, int channelId, const Position& creaturePos);
void processContainerAddItem(int containerId, const ItemPtr& item);
void processInventoryChange(int slot, const ItemPtr& item);
void processCreatureMove(const CreaturePtr& creature, const Position& oldPos, const Position& newPos);
@ -82,8 +82,8 @@ public:
// talk related
void talk(const std::string& message);
void talkChannel(const std::string& speakTypeDesc, int channelId, const std::string& message);
void talkPrivate(const std::string& speakTypeDesc, const std::string& receiver, const std::string& message);
void talkChannel(Otc::SpeakType speakType, int channelId, const std::string& message);
void talkPrivate(Otc::SpeakType speakType, const std::string& receiver, const std::string& message);
void openPrivateChannel(const std::string& receiver);
void requestChannels();
void joinChannel(int channelId);

@ -38,13 +38,13 @@ void StaticText::draw(const Point& dest, const Rect& parentRect)
boundRect.bind(parentRect);
// draw only if the real center is not too far from the parent center, or its a yell
if((boundRect.center() - rect.center()).length() < parentRect.width() / 15 || m_yell) {
if((boundRect.center() - rect.center()).length() < parentRect.width() / 15 || isYell()) {
//TODO: cache into a framebuffer
m_font->renderText(m_text, boundRect, Fw::AlignCenter, m_color);
}
}
bool StaticText::addMessage(const std::string& name, const std::string& type, const std::string& message)
bool StaticText::addMessage(const std::string& name, Otc::SpeakType type, const std::string& message)
{
//TODO: this could be moved to lua
// First message
@ -66,10 +66,6 @@ bool StaticText::addMessage(const std::string& name, const std::string& type, co
self->removeMessage();
}, std::max<int>(Otc::STATIC_DURATION_PER_CHARACTER * message.length(), Otc::MIN_STATIC_TEXT_DURATION));
if(type == "yell" || type == "monsterYell")
m_yell = true;
return true;
}
@ -90,21 +86,21 @@ void StaticText::compose()
//TODO: this could be moved to lua
std::string text;
if(m_messageType == "say") {
if(m_messageType == Otc::SpeakSay) {
text += m_name;
text += " says:\n";
m_color = Color(239, 239, 0);
} else if(m_messageType == "whisper") {
} else if(m_messageType == Otc::SpeakWhisper) {
text += m_name;
text += " whispers:\n";
m_color = Color(239, 239, 0);
} else if(m_messageType == "yell") {
} else if(m_messageType == Otc::SpeakYell) {
text += m_name;
text += " yells:\n";
m_color = Color(239, 239, 0);
} else if(m_messageType == "monsterSay" || m_messageType == "monsterYell") {
} else if(m_messageType == Otc::SpeakMonsterSay || m_messageType == Otc::SpeakMonsterYell) {
m_color = Color(254, 101, 0);
} else if(m_messageType == "npcToPlayer") {
} else if(m_messageType == Otc::SpeakPrivateNpcToPlayer) {
text += m_name;
text += " says:\n";
m_color = Color(95, 247, 247);

@ -34,12 +34,12 @@ public:
void draw(const Point& dest, const Rect& parentRect);
std::string getName() { return m_name; }
std::string getMessageType() { return m_messageType; }
Otc::SpeakType getMessageType() { return m_messageType; }
std::string getFirstMessage() { return m_messages[0]; }
bool isYell() { return m_yell; }
bool isYell() { return m_messageType == Otc::SpeakYell || m_messageType == Otc::SpeakMonsterYell; }
bool addMessage(const std::string& name, const std::string& type, const std::string& message);
bool addMessage(const std::string& name, Otc::SpeakType type, const std::string& message);
void removeMessage();
StaticTextPtr asStaticText() { return std::static_pointer_cast<StaticText>(shared_from_this()); }
@ -52,7 +52,7 @@ private:
Boolean<false> m_yell;
std::vector<std::string> m_messages;
std::string m_name, m_text;
std::string m_messageType;
Otc::SpeakType m_messageType;
Color m_color;
};

@ -220,47 +220,47 @@ namespace Proto {
ClientGetObjectInfo = 243
};
enum SpeakTypes {
enum ServerSpeakType {
#if PROTOCOL==862
SpeakSay = 1,
SpeakWhisper,
SpeakYell,
SpeakPrivatePlayerToNpc,
SpeakPrivateNpcToPlayer,
SpeakPrivate,
SpeakChannelYellow,
SpeakChannelWhite,
SpeakBroadcast,
SpeakChannelRed,
SpeakPrivateRed,
SpeakChannelOrange,
SpeakMonsterSay,
SpeakMonsterYell,
ServerSpeakSay = 1,
ServerSpeakWhisper,
ServerSpeakYell,
ServerSpeakPrivatePlayerToNpc,
ServerSpeakPrivateNpcToPlayer,
ServerSpeakPrivate,
ServerSpeakChannelYellow,
ServerSpeakChannelWhite,
ServerSpeakBroadcast,
ServerSpeakChannelRed,
ServerSpeakPrivateRed,
ServerSpeakChannelOrange,
ServerSpeakMonsterSay,
ServerSpeakMonsterYell,
// removed
SpeakRVRChannel = 255,
SpeakRVRAnswer,
SpeakRVRContinue,
SpeakChannelRed2
ServerSpeakRVRChannel = 255,
ServerSpeakRVRAnswer,
ServerSpeakRVRContinue,
ServerSpeakChannelRed2
#elif PROTOCOL==860
SpeakSay = 1,
SpeakWhisper,
SpeakYell,
SpeakPrivatePlayerToNpc,
SpeakPrivateNpcToPlayer,
SpeakPrivate,
SpeakChannelYellow,
SpeakChannelWhite,
SpeakRVRChannel,
SpeakRVRAnswer,
SpeakRVRContinue,
SpeakBroadcast,
SpeakChannelRed,
SpeakPrivateRed,
SpeakChannelOrange,
SpeakChannelRed2 = 17,
SpeakMonsterSay = 19,
SpeakMonsterYell
ServerSpeakSay = 1,
ServerSpeakWhisper,
ServerSpeakYell,
ServerSpeakPrivatePlayerToNpc,
ServerSpeakPrivateNpcToPlayer,
ServerSpeakPrivate,
ServerSpeakChannelYellow,
ServerSpeakChannelWhite,
ServerSpeakRVRChannel,
ServerSpeakRVRAnswer,
ServerSpeakRVRContinue,
ServerSpeakBroadcast,
ServerSpeakChannelRed,
ServerSpeakPrivateRed,
ServerSpeakChannelOrange,
ServerSpeakChannelRed2 = 17,
ServerSpeakMonsterSay = 19,
ServerSpeakMonsterYell
#endif
};
@ -299,48 +299,48 @@ namespace Proto {
NpcEndId = 0xffffffff
};
inline std::string translateSpeakType(int type) {
inline Otc::SpeakType translateSpeakTypeFromServer(int type) {
switch(type) {
case Proto::SpeakSay: return "say";
case Proto::SpeakWhisper: return "whisper";
case Proto::SpeakYell: return "yell";
case Proto::SpeakMonsterSay: return "monsterSay";
case Proto::SpeakMonsterYell: return "monsterYell";
case Proto::SpeakPrivateNpcToPlayer: return "npcToPlayer";
case Proto::SpeakChannelYellow: return "channelYellow";
case Proto::SpeakChannelWhite: return "channelWhite";
case Proto::SpeakChannelRed: return "channelRed";
case Proto::SpeakChannelRed2: return "channelRed";
case Proto::SpeakChannelOrange: return "channelOrange";
case Proto::SpeakPrivate: return "private";
case Proto::SpeakPrivatePlayerToNpc: return "playerToNpc";
case Proto::SpeakBroadcast: return "broadcast";
case Proto::SpeakPrivateRed: return "privateRed";
case Proto::ServerSpeakSay: return Otc::SpeakSay;
case Proto::ServerSpeakWhisper: return Otc::SpeakWhisper;
case Proto::ServerSpeakYell: return Otc::SpeakYell;
case Proto::ServerSpeakMonsterSay: return Otc::SpeakMonsterSay;
case Proto::ServerSpeakMonsterYell: return Otc::SpeakMonsterYell;
case Proto::ServerSpeakPrivateNpcToPlayer: return Otc::SpeakPrivateNpcToPlayer;
case Proto::ServerSpeakChannelYellow: return Otc::SpeakChannelYellow;
case Proto::ServerSpeakChannelWhite: return Otc::SpeakChannelWhite;
case Proto::ServerSpeakChannelRed: return Otc::SpeakChannelRed;
case Proto::ServerSpeakChannelRed2: return Otc::SpeakChannelRed;
case Proto::ServerSpeakChannelOrange: return Otc::SpeakChannelOrange;
case Proto::ServerSpeakPrivate: return Otc::SpeakPrivate;
case Proto::ServerSpeakPrivatePlayerToNpc: return Otc::SpeakPrivate;
case Proto::ServerSpeakBroadcast: return Otc::SpeakBroadcast;
case Proto::ServerSpeakPrivateRed: return Otc::SpeakPrivateRed;
default:
logError("unknown protocol speak type ", type);
return "unknown";
return Otc::SpeakSay;
}
}
inline int translateSpeakTypeDesc(const std::string& type) {
if(type == "say") return Proto::SpeakSay;
else if(type == "whisper") return Proto::SpeakWhisper;
else if(type == "yell") return Proto::SpeakYell;
else if(type == "monsterSay") return Proto::SpeakMonsterSay;
else if(type == "monsterYell") return Proto::SpeakMonsterYell;
else if(type == "npcToPlayer") return Proto::SpeakPrivateNpcToPlayer;
else if(type == "channelYellow") return Proto::SpeakChannelYellow;
else if(type == "channelWhite") return Proto::SpeakChannelWhite;
else if(type == "channelRed") return Proto::SpeakChannelRed;
else if(type == "channelRed") return Proto::SpeakChannelRed2;
else if(type == "channelOrange") return Proto::SpeakChannelOrange;
else if(type == "private") return Proto::SpeakPrivate;
else if(type == "playerToNpc") return Proto::SpeakPrivatePlayerToNpc;
else if(type == "broadcast") return Proto::SpeakBroadcast;
else if(type == "privateRed") return Proto::SpeakPrivateRed;
else {
logError("unknown protocol speak type desc ", type);
return 0;
inline Proto::ServerSpeakType translateSpeakTypeToServer(int type) {
switch(type) {
case Otc::SpeakSay: return Proto::ServerSpeakSay;
case Otc::SpeakWhisper: return Proto::ServerSpeakWhisper;
case Otc::SpeakYell: return Proto::ServerSpeakYell;
case Otc::SpeakBroadcast: return Proto::ServerSpeakBroadcast;
case Otc::SpeakPrivate: return Proto::ServerSpeakPrivate;
case Otc::SpeakPrivateRed: return Proto::ServerSpeakPrivateRed;
case Otc::SpeakPrivatePlayerToNpc: return Proto::ServerSpeakPrivatePlayerToNpc;
case Otc::SpeakPrivateNpcToPlayer: return Proto::ServerSpeakPrivateNpcToPlayer;
case Otc::SpeakChannelYellow: return Proto::ServerSpeakChannelYellow;
case Otc::SpeakChannelWhite: return Proto::ServerSpeakChannelWhite;
case Otc::SpeakChannelRed: return Proto::ServerSpeakChannelRed;
case Otc::SpeakChannelOrange: return Proto::ServerSpeakChannelOrange;
case Otc::SpeakMonsterSay: return Proto::ServerSpeakMonsterSay;
case Otc::SpeakMonsterYell: return Proto::ServerSpeakMonsterYell;
default:
logError("unknown protocol speak type desc ", type);
return Proto::ServerSpeakSay;
}
}

@ -73,7 +73,7 @@ public:
void sendTextWindow(uint windowTextId, const std::string& text);
void sendHouseWindow(int doorId, uint id, const std::string& text);
void sendLookAt(const Position& position, int thingId, int stackpos);
void sendTalk(const std::string& speakTypeDesc, int channelId, const std::string& receiver, const std::string& message);
void sendTalk(Otc::SpeakType speakType, int channelId, const std::string& receiver, const std::string& message);
void sendGetChannels();
void sendJoinChannel(int channelId);
void sendLeaveChannel(int channelId);

@ -720,43 +720,43 @@ void ProtocolGame::parseCreatureSpeak(InputMessage& msg)
msg.getU32(); // unkSpeak
std::string name = msg.getString();
int level = msg.getU16();
int type = msg.getU8();
int serverType = msg.getU8();
int channelId = 0;
Position creaturePos;
switch(type) {
case Proto::SpeakSay:
case Proto::SpeakWhisper:
case Proto::SpeakYell:
case Proto::SpeakMonsterSay:
case Proto::SpeakMonsterYell:
case Proto::SpeakPrivateNpcToPlayer:
switch(serverType) {
case Proto::ServerSpeakSay:
case Proto::ServerSpeakWhisper:
case Proto::ServerSpeakYell:
case Proto::ServerSpeakMonsterSay:
case Proto::ServerSpeakMonsterYell:
case Proto::ServerSpeakPrivateNpcToPlayer:
creaturePos = parsePosition(msg);
break;
case Proto::SpeakChannelYellow:
case Proto::SpeakChannelWhite:
case Proto::SpeakChannelRed:
case Proto::SpeakChannelRed2:
case Proto::SpeakChannelOrange:
case Proto::ServerSpeakChannelYellow:
case Proto::ServerSpeakChannelWhite:
case Proto::ServerSpeakChannelRed:
case Proto::ServerSpeakChannelRed2:
case Proto::ServerSpeakChannelOrange:
channelId = msg.getU16();
break;
case Proto::SpeakPrivate:
case Proto::SpeakPrivatePlayerToNpc:
case Proto::SpeakBroadcast:
case Proto::SpeakPrivateRed:
case Proto::ServerSpeakPrivate:
case Proto::ServerSpeakPrivatePlayerToNpc:
case Proto::ServerSpeakBroadcast:
case Proto::ServerSpeakPrivateRed:
break;
case Proto::SpeakRVRChannel:
case Proto::ServerSpeakRVRChannel:
msg.getU32();
break;
default:
logTraceError("unknown speak type ", type);
logTraceError("unknown speak type ", serverType);
break;
}
std::string message = msg.getString();
std::string typeDesc = Proto::translateSpeakType(type);
Otc::SpeakType type = Proto::translateSpeakTypeFromServer(serverType);
g_game.processCreatureSpeak(name, level, typeDesc, message, channelId, creaturePos);
g_game.processCreatureSpeak(name, level, type, message, channelId, creaturePos);
}
void ProtocolGame::parseChannelList(InputMessage& msg)

@ -341,24 +341,24 @@ void ProtocolGame::sendLookAt(const Position& position, int thingId, int stackpo
send(oMsg);
}
void ProtocolGame::sendTalk(const std::string& speakTypeDesc, int channelId, const std::string& receiver, const std::string& message)
void ProtocolGame::sendTalk(Otc::SpeakType speakType, int channelId, const std::string& receiver, const std::string& message)
{
if(message.length() > 255 || message.length() <= 0)
return;
int speakType = Proto::translateSpeakTypeDesc(speakTypeDesc);
int serverSpeakType = Proto::translateSpeakTypeToServer(speakType);
OutputMessage oMsg;
oMsg.addU8(Proto::ClientTalk);
oMsg.addU8(speakType);
oMsg.addU8(serverSpeakType);
switch(speakType) {
case Proto::SpeakPrivate:
case Proto::SpeakPrivateRed:
switch(serverSpeakType) {
case Proto::ServerSpeakPrivate:
case Proto::ServerSpeakPrivateRed:
oMsg.addString(receiver);
break;
case Proto::SpeakChannelYellow:
case Proto::SpeakChannelRed:
case Proto::ServerSpeakChannelYellow:
case Proto::ServerSpeakChannelRed:
oMsg.addU16(channelId);
break;
}

Loading…
Cancel
Save