rework speak types

This commit is contained in:
Eduardo Bart 2012-02-02 22:25:18 -02:00
parent fa915e088c
commit 05f649cdeb
11 changed files with 156 additions and 131 deletions

View File

@ -298,3 +298,18 @@ KeyCodeDescs = {
[KeyNumpad8] = 'Numpad8', [KeyNumpad8] = 'Numpad8',
[KeyNumpad9] = 'Numpad9' [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

View File

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

View File

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

View File

@ -172,9 +172,9 @@ void Game::processTextMessage(const std::string& type, const std::string& messag
g_lua.callGlobalField("Game","onTextMessage", type, message); 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); StaticTextPtr staticText = StaticTextPtr(new StaticText);
staticText->addMessage(name, type, message); staticText->addMessage(name, type, message);
g_map.addThing(staticText, creaturePos); g_map.addThing(staticText, creaturePos);
@ -461,24 +461,23 @@ int Game::getThingStackpos(const ThingPtr& thing)
void Game::talk(const std::string& message) 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()) if(!isOnline() || !checkBotProtection())
return; 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()) if(!isOnline() || !checkBotProtection())
return; return;
m_protocolGame->sendTalk(speakTypeDesc, 0, receiver, message); m_protocolGame->sendTalk(speakType, 0, receiver, message);
} }
void Game::openPrivateChannel(const std::string& receiver) void Game::openPrivateChannel(const std::string& receiver)
{ {
if(!isOnline() || !checkBotProtection()) if(!isOnline() || !checkBotProtection())

View File

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

View File

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

View File

@ -34,12 +34,12 @@ public:
void draw(const Point& dest, const Rect& parentRect); void draw(const Point& dest, const Rect& parentRect);
std::string getName() { return m_name; } 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]; } 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(); void removeMessage();
StaticTextPtr asStaticText() { return std::static_pointer_cast<StaticText>(shared_from_this()); } StaticTextPtr asStaticText() { return std::static_pointer_cast<StaticText>(shared_from_this()); }
@ -52,7 +52,7 @@ private:
Boolean<false> m_yell; Boolean<false> m_yell;
std::vector<std::string> m_messages; std::vector<std::string> m_messages;
std::string m_name, m_text; std::string m_name, m_text;
std::string m_messageType; Otc::SpeakType m_messageType;
Color m_color; Color m_color;
}; };

View File

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

View File

@ -73,7 +73,7 @@ public:
void sendTextWindow(uint windowTextId, const std::string& text); void sendTextWindow(uint windowTextId, const std::string& text);
void sendHouseWindow(int doorId, uint id, const std::string& text); void sendHouseWindow(int doorId, uint id, const std::string& text);
void sendLookAt(const Position& position, int thingId, int stackpos); 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 sendGetChannels();
void sendJoinChannel(int channelId); void sendJoinChannel(int channelId);
void sendLeaveChannel(int channelId); void sendLeaveChannel(int channelId);

View File

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

View File

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