add combat controls

This commit is contained in:
Eduardo Bart
2012-02-07 21:06:52 -02:00
parent e51789378a
commit ee1357a848
21 changed files with 293 additions and 8 deletions

View File

@@ -211,7 +211,7 @@ namespace Otc
};
enum ChaseModes {
StandWhileFighting = 0,
DontChase = 0,
ChaseOpponent = 1
};

View File

@@ -77,6 +77,12 @@ void Game::processLogin(const LocalPlayerPtr& localPlayer, int serverBeat)
m_localPlayer = localPlayer;
m_serverBeat = serverBeat;
// synchronize fight modes with the server
m_fightMode = Otc::FightBalanced;
m_chaseMode = Otc::DontChase;
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);
}
@@ -384,6 +390,33 @@ void Game::move(const ThingPtr& thing, const Position& toPos, int count)
m_protocolGame->sendThrow(thing->getPosition(), thing->getId(), thing->getStackpos(), toPos, count);
}
void Game::setChaseMode(Otc::ChaseModes chaseMode)
{
if(!isOnline() || !checkBotProtection())
return;
m_chaseMode = chaseMode;
m_protocolGame->sendFightTatics(m_fightMode, m_chaseMode, m_safeFight);
}
void Game::setFightMode(Otc::FightModes fightMode)
{
if(!isOnline() || !checkBotProtection())
return;
m_fightMode = fightMode;
m_protocolGame->sendFightTatics(m_fightMode, m_chaseMode, m_safeFight);
}
void Game::setSafeFight(bool on)
{
if(!isOnline() || !checkBotProtection())
return;
m_safeFight = on;
m_protocolGame->sendFightTatics(m_fightMode, m_chaseMode, m_safeFight);
}
void Game::attack(const CreaturePtr& creature)
{
if(!isOnline() || !creature || !checkBotProtection())

View File

@@ -74,6 +74,14 @@ public:
void useInventoryItemWith(int itemId, const ThingPtr& toThing);
void move(const ThingPtr &thing, const Position& toPos, int count);
// fight tatics related
void setChaseMode(Otc::ChaseModes chaseMode);
void setFightMode(Otc::FightModes fightMode);
void setSafeFight(bool on);
Otc::ChaseModes getChaseMode() { return m_chaseMode; }
Otc::FightModes getFightMode() { return m_fightMode; }
bool isSafeFight() { return m_safeFight; }
// attack/follow related
void attack(const CreaturePtr& creature);
void cancelAttack();
@@ -124,6 +132,10 @@ private:
ProtocolGamePtr m_protocolGame;
bool m_dead;
int m_serverBeat;
Otc::FightModes m_fightMode;
Otc::ChaseModes m_chaseMode;
bool m_safeFight;
};
extern Game g_game;

View File

@@ -204,6 +204,12 @@ void OTClient::registerLuaFunctions()
g_lua.bindClassStaticFunction<Game>("turn", std::bind(&Game::turn, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("walk", std::bind(&Game::walk, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("forceWalk", std::bind(&Game::forceWalk, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("setChaseMode", std::bind(&Game::setChaseMode, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("setFightMode", std::bind(&Game::setFightMode, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("setSafeFight", std::bind(&Game::setSafeFight, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("getChaseMode", std::bind(&Game::getChaseMode, &g_game));
g_lua.bindClassStaticFunction<Game>("getFightMode", std::bind(&Game::getFightMode, &g_game));
g_lua.bindClassStaticFunction<Game>("isSafeFight", std::bind(&Game::isSafeFight, &g_game));
g_lua.bindClassStaticFunction<Game>("attack", std::bind(&Game::attack, &g_game, _1));
g_lua.bindClassStaticFunction<Game>("cancelAttack", std::bind(&Game::cancelAttack, &g_game));
g_lua.bindClassStaticFunction<Game>("follow", std::bind(&Game::follow, &g_game, _1));