mirror of
https://github.com/edubart/otclient.git
synced 2025-10-15 03:54:54 +02:00
simplistic autowalk
* add simple and stupid autowalk algorithm * fix issue in classic control
This commit is contained in:
@@ -372,7 +372,7 @@ void Game::walk(Otc::Direction direction)
|
||||
forceWalk(direction);
|
||||
}
|
||||
|
||||
void Game::walkPath(const std::vector<Otc::Direction>& dir)
|
||||
void Game::autoWalk(const std::vector<Otc::Direction>& dir)
|
||||
{
|
||||
if(!canPerformGameAction())
|
||||
return;
|
||||
@@ -380,7 +380,7 @@ void Game::walkPath(const std::vector<Otc::Direction>& dir)
|
||||
if(isFollowing())
|
||||
cancelFollow();
|
||||
|
||||
m_protocolGame->sendWalkPath(dir);
|
||||
m_protocolGame->sendAutoWalk(dir);
|
||||
}
|
||||
|
||||
void Game::forceWalk(Otc::Direction direction)
|
||||
|
@@ -123,7 +123,7 @@ public:
|
||||
|
||||
// walk related
|
||||
void walk(Otc::Direction direction);
|
||||
void walkPath(const std::vector<Otc::Direction>& dir);
|
||||
void autoWalk(const std::vector<Otc::Direction>& dir);
|
||||
void forceWalk(Otc::Direction direction);
|
||||
void turn(Otc::Direction direction);
|
||||
void stop();
|
||||
|
@@ -82,7 +82,7 @@ void OTClient::registerLuaFunctions()
|
||||
g_lua.bindClassStaticFunction("g_game", "forceLogout", std::bind(&Game::forceLogout, &g_game));
|
||||
g_lua.bindClassStaticFunction("g_game", "safeLogout", std::bind(&Game::safeLogout, &g_game));
|
||||
g_lua.bindClassStaticFunction("g_game", "walk", std::bind(&Game::walk, &g_game, _1));
|
||||
g_lua.bindClassStaticFunction("g_game", "walkPath", std::bind(&Game::walkPath, &g_game, _1));
|
||||
g_lua.bindClassStaticFunction("g_game", "autoWalk", std::bind(&Game::autoWalk, &g_game, _1));
|
||||
g_lua.bindClassStaticFunction("g_game", "forceWalk", std::bind(&Game::forceWalk, &g_game, _1));
|
||||
g_lua.bindClassStaticFunction("g_game", "turn", std::bind(&Game::turn, &g_game, _1));
|
||||
g_lua.bindClassStaticFunction("g_game", "stop", std::bind(&Game::stop, &g_game));
|
||||
|
@@ -155,7 +155,7 @@ namespace Proto {
|
||||
ClientEnterGame = 10,
|
||||
ClientLeaveGame = 20,
|
||||
ClientPingResponse = 30,
|
||||
ClientWalkPath = 100,
|
||||
ClientAutoWalk = 100,
|
||||
ClientWalkNorth = 101,
|
||||
ClientWalkEast = 102,
|
||||
ClientWalkSouth = 103,
|
||||
|
@@ -42,7 +42,7 @@ public:
|
||||
|
||||
void sendLogout();
|
||||
void sendPingResponse();
|
||||
void sendWalkPath(const std::vector<Otc::Direction>& path);
|
||||
void sendAutoWalk(const std::vector<Otc::Direction>& path);
|
||||
void sendWalkNorth();
|
||||
void sendWalkEast();
|
||||
void sendWalkSouth();
|
||||
|
@@ -79,12 +79,44 @@ void ProtocolGame::sendPingResponse()
|
||||
send(msg);
|
||||
}
|
||||
|
||||
void ProtocolGame::sendWalkPath(const std::vector<Otc::Direction>& path)
|
||||
void ProtocolGame::sendAutoWalk(const std::vector<Otc::Direction>& path)
|
||||
{
|
||||
OutputMessage msg;
|
||||
msg.addU8(Proto::ClientAutoWalk);
|
||||
msg.addU8(path.size());
|
||||
for(Otc::Direction dir : path)
|
||||
msg.addU8(dir);
|
||||
for(Otc::Direction dir : path) {
|
||||
uint8 byte;
|
||||
switch(dir) {
|
||||
case Otc::East:
|
||||
byte = 1;
|
||||
break;
|
||||
case Otc::NorthEast:
|
||||
byte = 2;
|
||||
break;
|
||||
case Otc::North:
|
||||
byte = 3;
|
||||
break;
|
||||
case Otc::NorthWest:
|
||||
byte = 4;
|
||||
break;
|
||||
case Otc::West:
|
||||
byte = 5;
|
||||
break;
|
||||
case Otc::SouthWest:
|
||||
byte = 6;
|
||||
break;
|
||||
case Otc::South:
|
||||
byte = 7;
|
||||
break;
|
||||
case Otc::SouthEast:
|
||||
byte = 8;
|
||||
break;
|
||||
default:
|
||||
byte = 0;
|
||||
break;
|
||||
}
|
||||
msg.addU8(byte);
|
||||
}
|
||||
send(msg);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user