mirror of
https://github.com/edubart/otclient.git
synced 2025-10-14 11:34:54 +02:00
add onGameStart/onGameEnd/onLogin/onLogout events
This commit is contained in:
@@ -72,7 +72,7 @@ void Game::processConnectionError(const boost::system::error_code& error)
|
||||
}
|
||||
}
|
||||
|
||||
void Game::processLogin(const LocalPlayerPtr& localPlayer, int serverBeat)
|
||||
void Game::processGameStart(const LocalPlayerPtr& localPlayer, int serverBeat)
|
||||
{
|
||||
m_localPlayer = localPlayer;
|
||||
m_serverBeat = serverBeat;
|
||||
@@ -83,8 +83,16 @@ void Game::processLogin(const LocalPlayerPtr& localPlayer, int serverBeat)
|
||||
m_safeFight = true;
|
||||
m_protocolGame->sendFightTatics(m_fightMode, m_chaseMode, m_safeFight);
|
||||
|
||||
// NOTE: the entire map description is not known yet
|
||||
g_lua.callGlobalField("Game", "onLogin", localPlayer);
|
||||
// NOTE: the entire map description and local player informations is not known yet
|
||||
g_lua.callGlobalField("Game", "onGameStart");
|
||||
}
|
||||
|
||||
void Game::processLogin()
|
||||
{
|
||||
if(!isOnline())
|
||||
return;
|
||||
|
||||
g_lua.callGlobalField("Game", "onLogin", m_localPlayer);
|
||||
}
|
||||
|
||||
void Game::processLogout()
|
||||
@@ -93,6 +101,8 @@ void Game::processLogout()
|
||||
g_lua.callGlobalField("Game", "onLogout", m_localPlayer);
|
||||
|
||||
m_localPlayer = nullptr;
|
||||
|
||||
g_lua.callGlobalField("Game", "onGameEnd");
|
||||
}
|
||||
|
||||
if(m_protocolGame) {
|
||||
|
@@ -42,7 +42,8 @@ public:
|
||||
void cleanLogout() { logout(false); }
|
||||
void processLoginError(const std::string& error);
|
||||
void processConnectionError(const boost::system::error_code& error);
|
||||
void processLogin(const LocalPlayerPtr& localPlayer, int serverBeat);
|
||||
void processGameStart(const LocalPlayerPtr& localPlayer, int serverBeat);
|
||||
void processLogin();
|
||||
void processLogout();
|
||||
void processDeath();
|
||||
void processPlayerStats(double health, double maxHealth,
|
||||
|
@@ -38,11 +38,11 @@ Tile::Tile(const Position& position)
|
||||
|
||||
void Tile::draw(const Point& dest, float scaleFactor, int drawFlags)
|
||||
{
|
||||
m_drawElevation = 0;
|
||||
bool animate = drawFlags & Otc::DrawAnimations;
|
||||
|
||||
// first bottom items
|
||||
if(drawFlags & (Otc::DrawGround | Otc::DrawGroundBorders | Otc::DrawOnBottom)) {
|
||||
m_drawElevation = 0;
|
||||
for(const ThingPtr& thing : m_things) {
|
||||
if(!thing->isGround() && !thing->isGroundBorder() && !thing->isOnBottom())
|
||||
break;
|
||||
|
@@ -106,7 +106,7 @@ private:
|
||||
// Parse Messages
|
||||
void parseMessage(InputMessage& msg);
|
||||
|
||||
void parsePlayerLogin(InputMessage& msg);
|
||||
void parseInitGame(InputMessage& msg);
|
||||
void parseGMActions(InputMessage& msg);
|
||||
void parseLoginError(InputMessage& msg);
|
||||
void parseFYIMessage(InputMessage& msg);
|
||||
|
@@ -41,7 +41,7 @@ void ProtocolGame::parseMessage(InputMessage& msg)
|
||||
|
||||
switch(opt) {
|
||||
case Proto::GameServerInitGame:
|
||||
parsePlayerLogin(msg);
|
||||
parseInitGame(msg);
|
||||
break;
|
||||
case Proto::GameServerGMActions:
|
||||
parseGMActions(msg);
|
||||
@@ -265,7 +265,7 @@ void ProtocolGame::parseMessage(InputMessage& msg)
|
||||
}
|
||||
}
|
||||
|
||||
void ProtocolGame::parsePlayerLogin(InputMessage& msg)
|
||||
void ProtocolGame::parseInitGame(InputMessage& msg)
|
||||
{
|
||||
uint playerId = msg.getU32();
|
||||
int serverBeat = msg.getU16();
|
||||
@@ -274,7 +274,7 @@ void ProtocolGame::parsePlayerLogin(InputMessage& msg)
|
||||
m_localPlayer = LocalPlayerPtr(new LocalPlayer);
|
||||
m_localPlayer->setId(playerId);
|
||||
m_localPlayer->setCanReportBugs(playerCanReportBugs);
|
||||
g_game.processLogin(m_localPlayer, serverBeat);
|
||||
g_game.processGameStart(m_localPlayer, serverBeat);
|
||||
}
|
||||
|
||||
void ProtocolGame::parseGMActions(InputMessage& msg)
|
||||
@@ -1110,8 +1110,10 @@ ThingPtr ProtocolGame::internalGetThing(InputMessage& msg)
|
||||
creature->setPassable(passable);
|
||||
creature->setDirection(direction);
|
||||
|
||||
// now that the local player is known, we can schedule login event
|
||||
if(creature == m_localPlayer) {
|
||||
m_localPlayer->setKnown(true);
|
||||
g_dispatcher.addEvent([] { g_game.processLogin(); });
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user