2011-08-15 16:11:24 +02:00
|
|
|
#include "game.h"
|
2011-08-15 23:02:52 +02:00
|
|
|
#include "localplayer.h"
|
2011-08-16 02:30:31 +02:00
|
|
|
#include <otclient/net/protocolgame.h>
|
2011-08-15 16:11:24 +02:00
|
|
|
|
|
|
|
Game g_game;
|
|
|
|
|
2011-08-16 02:30:31 +02:00
|
|
|
void Game::init()
|
2011-08-15 16:11:24 +02:00
|
|
|
{
|
|
|
|
m_online = false;
|
|
|
|
}
|
2011-08-15 23:02:52 +02:00
|
|
|
|
2011-08-16 02:30:31 +02:00
|
|
|
void Game::terminate()
|
|
|
|
{
|
|
|
|
if(m_online)
|
|
|
|
logout();
|
|
|
|
}
|
|
|
|
|
2011-08-26 20:00:22 +02:00
|
|
|
void Game::loginWorld(const std::string& account, const std::string& password, const std::string& worldHost, int worldPort, const std::string& characterName)
|
2011-08-16 02:30:31 +02:00
|
|
|
{
|
|
|
|
m_protocolGame = ProtocolGamePtr(new ProtocolGame);
|
2011-08-26 20:00:22 +02:00
|
|
|
m_protocolGame->login(account, password, worldHost, (uint16)worldPort, characterName);
|
2011-08-16 02:30:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Game::logout()
|
|
|
|
{
|
|
|
|
m_protocolGame->sendLogout();
|
|
|
|
onLogout();
|
|
|
|
}
|
|
|
|
|
2011-08-15 23:02:52 +02:00
|
|
|
void Game::onLogin()
|
|
|
|
{
|
|
|
|
m_localPlayer = LocalPlayerPtr(new LocalPlayer);
|
|
|
|
m_online = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::onLogout()
|
|
|
|
{
|
2011-08-16 05:27:46 +02:00
|
|
|
if(m_protocolGame) {
|
|
|
|
m_protocolGame->disconnect();
|
|
|
|
m_protocolGame.reset();
|
|
|
|
}
|
2011-08-15 23:02:52 +02:00
|
|
|
m_localPlayer.reset();
|
|
|
|
m_online = false;
|
|
|
|
}
|
2011-08-17 06:45:55 +02:00
|
|
|
|
|
|
|
void Game::walk(Direction direction)
|
|
|
|
{
|
|
|
|
if(!m_online)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// TODO: check if we can walk.
|
|
|
|
|
|
|
|
m_localPlayer->setDirection(direction);
|
|
|
|
|
|
|
|
switch(direction) {
|
|
|
|
case DIRECTION_NORTH:
|
|
|
|
m_protocolGame->sendWalkNorth();
|
|
|
|
break;
|
|
|
|
case DIRECTION_EAST:
|
|
|
|
m_protocolGame->sendWalkEast();
|
|
|
|
break;
|
|
|
|
case DIRECTION_SOUTH:
|
|
|
|
m_protocolGame->sendWalkSouth();
|
|
|
|
break;
|
|
|
|
case DIRECTION_WEST:
|
|
|
|
m_protocolGame->sendWalkWest();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Game::turn(Direction direction)
|
|
|
|
{
|
|
|
|
if(!m_online)
|
|
|
|
return;
|
|
|
|
|
|
|
|
switch(direction) {
|
|
|
|
case DIRECTION_NORTH:
|
|
|
|
m_protocolGame->sendTurnNorth();
|
|
|
|
break;
|
|
|
|
case DIRECTION_EAST:
|
|
|
|
m_protocolGame->sendTurnEast();
|
|
|
|
break;
|
|
|
|
case DIRECTION_SOUTH:
|
|
|
|
m_protocolGame->sendTurnSouth();
|
|
|
|
break;
|
|
|
|
case DIRECTION_WEST:
|
|
|
|
m_protocolGame->sendTurnWest();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|