creature distinction, look, remove textmessage bug

This commit is contained in:
Henrique Santiago 2011-12-30 16:14:50 -02:00
parent 88f36b0455
commit 1ca825a4b6
10 changed files with 63 additions and 11 deletions

View File

@ -30,8 +30,9 @@ function TextMessage.create()
end end
-- hooked events -- hooked events
function Game.onTextMessage(type, message) function TextMessage.onTextMessage(type, message)
local messageType = messageTypes[type - messageTypes.first] local messageType = messageTypes[type - messageTypes.first]
print(messageType.color)
if messageType.showOnConsole then if messageType.showOnConsole then
-- TODO -- TODO
@ -46,9 +47,9 @@ function Game.onTextMessage(type, message)
end end
label:setVisible(true) label:setVisible(true)
label:setForegroundColor(messageType.color)
label:setText(message) label:setText(message)
label:setStyle(messageType.windowLocation) label:setStyle(messageType.windowLocation)
label:setForegroundColor(messageType.color)
time = #message * 75 time = #message * 75
removeEvent(hideEvent) removeEvent(hideEvent)
@ -60,4 +61,5 @@ end
connect(Game, { onLogin = TextMessage.create, connect(Game, { onLogin = TextMessage.create,
onLogout = TextMessage.destroy }) onLogout = TextMessage.destroy,
onTextMessage = TextMessage.onTextMessage })

View File

@ -349,6 +349,14 @@ namespace Otc
SpeakMonsterYell = 0x0E //Yell orange SpeakMonsterYell = 0x0E //Yell orange
}; };
enum CreaturesIdRange {
PlayerStartId = 0x10000000,
PlayerEndId = 0x40000000,
MonsterStartId = 0x40000000,
MonsterEndId = 0x80000000,
NpcStartId = 0x80000000,
NpcEndId = 0xffffffff
};
} }
#endif #endif

View File

@ -22,6 +22,8 @@
#include "game.h" #include "game.h"
#include "localplayer.h" #include "localplayer.h"
#include "map.h"
#include "tile.h"
#include <otclient/net/protocolgame.h> #include <otclient/net/protocolgame.h>
#include <framework/core/eventdispatcher.h> #include <framework/core/eventdispatcher.h>
@ -154,6 +156,17 @@ void Game::turn(Otc::Direction direction)
} }
} }
void Game::look(const Position& position)
{
const TilePtr& tile = g_map.getTile(position);
if(tile) {
int stackpos = tile->getLookStackpos();
ThingPtr thing = tile->getThing(stackpos);
if(thing)
m_protocolGame->sendLookAt(position, thing->getId(), stackpos);
}
}
void Game::talkChannel(int channelType, int channelId, const std::string& message) void Game::talkChannel(int channelType, int channelId, const std::string& message)
{ {
if(!m_online) if(!m_online)

View File

@ -48,6 +48,7 @@ public:
void walk(Otc::Direction direction); void walk(Otc::Direction direction);
void turn(Otc::Direction direction); void turn(Otc::Direction direction);
void look(const Position& position);
void talkChannel(int channelType, int channelId, const std::string& message); void talkChannel(int channelType, int channelId, const std::string& message);
void talkPrivate(int channelType, const std::string& receiver, const std::string& message); void talkPrivate(int channelType, const std::string& receiver, const std::string& message);
void openOutfitWindow(); void openOutfitWindow();

View File

@ -181,6 +181,14 @@ ItemPtr Tile::getGround()
return nullptr; return nullptr;
} }
int Tile::getLookStackpos()
{
// TODO: this needs to be improved
// check if thing has look property.
// check other floors
return m_things.size() - 1;
}
bool Tile::isWalkable() bool Tile::isWalkable()
{ {
if(!getGround()) if(!getGround())
@ -257,11 +265,6 @@ bool Tile::canCopyName()
// TODO: // TODO:
/* /*
//Ranges for ID Creatures
#define PLAYER_ID_RANGE 0x10000000
#define MONSTER_ID_RANGE 0x40000000
#define NPC_ID_RANGE 0x80000000
Get menu options Get menu options

View File

@ -46,6 +46,7 @@ public:
int getDrawElevation() { return m_drawElevation; } int getDrawElevation() { return m_drawElevation; }
std::vector<CreaturePtr> getCreatures(); std::vector<CreaturePtr> getCreatures();
ItemPtr getGround(); ItemPtr getGround();
int getLookStackpos();
bool isWalkable(); bool isWalkable();
bool isFullGround(); bool isFullGround();
bool isFullyOpaque(); bool isFullyOpaque();

View File

@ -55,6 +55,7 @@ public:
void sendTurnSouth(); void sendTurnSouth();
void sendTurnWest(); void sendTurnWest();
void sendUseItem(const Position& position, int itemId, int stackpos, int index); void sendUseItem(const Position& position, int itemId, int stackpos, int index);
void sendLookAt(const Position& position, int thingId, int stackpos);
void sendTalk(int channelType, int channelId, const std::string& receiver, const std::string& message); void sendTalk(int channelType, int channelId, const std::string& receiver, const std::string& message);
void sendGetOutfit(); void sendGetOutfit();
void sendSetOutfit(const Outfit& outfit); void sendSetOutfit(const Outfit& outfit);

View File

@ -1062,7 +1062,7 @@ ThingPtr ProtocolGame::internalGetThing(InputMessage& msg)
uint16 thingId = msg.getU16(); uint16 thingId = msg.getU16();
if(thingId == 0x0061 || thingId == 0x0062) { // add new creature if(thingId == 0x0061 || thingId == 0x0062) { // add new creature
CreaturePtr creature = CreaturePtr(new Creature); CreaturePtr creature;
if(thingId == 0x0062) { //creature is known if(thingId == 0x0062) { //creature is known
uint32 id = msg.getU32(); uint32 id = msg.getU32();
@ -1070,19 +1070,29 @@ ThingPtr ProtocolGame::internalGetThing(InputMessage& msg)
CreaturePtr knownCreature = g_map.getCreatureById(id); CreaturePtr knownCreature = g_map.getCreatureById(id);
if(knownCreature) if(knownCreature)
creature = knownCreature; creature = knownCreature;
else
logFatal("Server says creature is known, but its not on creatures list.");
} }
else if(thingId == 0x0061) { //creature is not known else if(thingId == 0x0061) { //creature is not known
uint32 removeId = msg.getU32(); uint32 removeId = msg.getU32();
uint32 id = msg.getU32(); uint32 id = msg.getU32();
std::string name = msg.getString(); std::string name = msg.getString();
if(name.length() > 0) // every creature name must have a capital letter if(name.length() > 0) // every creature name must start with a capital letter
name[0] = toupper(name[0]); name[0] = toupper(name[0]);
g_map.removeCreatureById(removeId); g_map.removeCreatureById(removeId);
if(m_localPlayer->getId() == id) if(id == m_localPlayer->getId())
creature = m_localPlayer->asCreature(); creature = m_localPlayer->asCreature();
else if(id >= Otc::PlayerStartId && id < Otc::PlayerEndId)
creature = PlayerPtr(new Player)->asCreature();
else if(id >= Otc::MonsterStartId && id < Otc::MonsterEndId)
creature = CreaturePtr(new Creature);
else if(id >= Otc::NpcStartId && id < Otc::NpcEndId)
creature = CreaturePtr(new Creature);
else
logFatal("creature id is invalid");
creature->setId(id); creature->setId(id);
creature->setName(name); creature->setName(name);

View File

@ -168,6 +168,16 @@ void ProtocolGame::sendUseItem(const Position& position, int itemId, int stackpo
send(oMsg); send(oMsg);
} }
void ProtocolGame::sendLookAt(const Position& position, int thingId, int stackpos)
{
OutputMessage oMsg;
oMsg.addU8(Otc::ClientLook);
addPosition(oMsg, position);
oMsg.addU16(thingId);
oMsg.addU8(stackpos);
send(oMsg);
}
void ProtocolGame::sendTalk(int channelType, int channelId, const std::string& receiver, const std::string& message) void ProtocolGame::sendTalk(int channelType, int channelId, const std::string& receiver, const std::string& message)
{ {
if(message.length() > 255 || message.length() <= 0) if(message.length() > 255 || message.length() <= 0)

View File

@ -21,6 +21,7 @@
*/ */
#include "uimap.h" #include "uimap.h"
#include <otclient/core/game.h>
#include <otclient/core/map.h> #include <otclient/core/map.h>
#include <framework/otml/otml.h> #include <framework/otml/otml.h>
#include <framework/graphics/graphics.h> #include <framework/graphics/graphics.h>
@ -95,6 +96,8 @@ bool UIMap::onMousePress(const Point& mousePos, Fw::MouseButton button)
animatedText->setColor(12); animatedText->setColor(12);
animatedText->setText("8"); animatedText->setText("8");
g_map.addThing(animatedText, g_map.getCentralPosition()); g_map.addThing(animatedText, g_map.getCentralPosition());
g_game.look(tilePos);
} }
} }