Fix silly for 963 and improve walk

This commit is contained in:
Eduardo Bart 2012-08-29 12:41:04 -03:00
parent 97e1c9d5a9
commit 9bd983ab51
3 changed files with 29 additions and 34 deletions

View File

@ -41,18 +41,18 @@ function init()
end end
function bindKeys() function bindKeys()
g_keyboard.bindKeyPress('Up', smartWalk, gameRootPanel, WALK_AUTO_REPEAT_DELAY) g_keyboard.bindKeyPress('Up', function() smartWalk(North) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Right', smartWalk, gameRootPanel, WALK_AUTO_REPEAT_DELAY) g_keyboard.bindKeyPress('Right', function() smartWalk(East) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Down', smartWalk, gameRootPanel, WALK_AUTO_REPEAT_DELAY) g_keyboard.bindKeyPress('Down', function() smartWalk(South) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Left', smartWalk, gameRootPanel, WALK_AUTO_REPEAT_DELAY) g_keyboard.bindKeyPress('Left', function() smartWalk(West) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Numpad8', function() g_game.walk(North) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY) g_keyboard.bindKeyPress('Numpad8', function() smartWalk(North) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Numpad9', function() g_game.walk(NorthEast) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY) g_keyboard.bindKeyPress('Numpad9', function() smartWalk(NorthEast) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Numpad6', function() g_game.walk(East) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY) g_keyboard.bindKeyPress('Numpad6', function() smartWalk(East) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Numpad3', function() g_game.walk(SouthEast) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY) g_keyboard.bindKeyPress('Numpad3', function() smartWalk(SouthEast) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Numpad2', function() g_game.walk(South) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY) g_keyboard.bindKeyPress('Numpad2', function() smartWalk(South) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Numpad1', function() g_game.walk(SouthWest) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY) g_keyboard.bindKeyPress('Numpad1', function() smartWalk(SouthWest) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Numpad4', function() g_game.walk(West) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY) g_keyboard.bindKeyPress('Numpad4', function() smartWalk(West) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Numpad7', function() g_game.walk(NorthWest) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY) g_keyboard.bindKeyPress('Numpad7', function() smartWalk(NorthWest) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Ctrl+Up', function() g_game.turn(North) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY) g_keyboard.bindKeyPress('Ctrl+Up', function() g_game.turn(North) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Ctrl+Right', function() g_game.turn(East) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY) g_keyboard.bindKeyPress('Ctrl+Right', function() g_game.turn(East) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
g_keyboard.bindKeyPress('Ctrl+Down', function() g_game.turn(South) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY) g_keyboard.bindKeyPress('Ctrl+Down', function() g_game.turn(South) end, gameRootPanel, WALK_AUTO_REPEAT_DELAY)
@ -152,7 +152,7 @@ function tryLogout()
anchor=AnchorHorizontalCenter}, yesCallback, noCallback) anchor=AnchorHorizontalCenter}, yesCallback, noCallback)
end end
function smartWalk() function smartWalk(defaultDir)
local dir local dir
if Options.getOption('smartWalk') then if Options.getOption('smartWalk') then
if g_keyboard.isKeyPressed('Up') and g_keyboard.isKeyPressed('Left') then if g_keyboard.isKeyPressed('Up') and g_keyboard.isKeyPressed('Left') then
@ -166,15 +166,7 @@ function smartWalk()
end end
end end
if not dir then if not dir then
if g_keyboard.isKeyPressed('Up') then dir = defaultDir
dir = North
elseif g_keyboard.isKeyPressed('Down') then
dir = South
elseif g_keyboard.isKeyPressed('Left') then
dir = West
elseif g_keyboard.isKeyPressed('Right') then
dir = East
end
end end
if Options.getOption('walkBooster') then if Options.getOption('walkBooster') then

View File

@ -467,10 +467,10 @@ void Game::safeLogout()
m_protocolGame->sendLogout(); m_protocolGame->sendLogout();
} }
void Game::walk(Otc::Direction direction) bool Game::walk(Otc::Direction direction)
{ {
if(!canPerformGameAction()) if(!canPerformGameAction())
return; return false;
// must cancel follow before any new walk // must cancel follow before any new walk
if(isFollowing()) if(isFollowing())
@ -479,11 +479,11 @@ void Game::walk(Otc::Direction direction)
// msut cancel auto walking and wait next try // msut cancel auto walking and wait next try
if(m_localPlayer->isAutoWalking()) { if(m_localPlayer->isAutoWalking()) {
m_protocolGame->sendStop(); m_protocolGame->sendStop();
return; return false;
} }
if(!m_localPlayer->canWalk(direction)) if(!m_localPlayer->canWalk(direction))
return; return false;
Position toPos = m_localPlayer->getPosition().translatedToDirection(direction); Position toPos = m_localPlayer->getPosition().translatedToDirection(direction);
TilePtr toTile = g_map.getTile(toPos); TilePtr toTile = g_map.getTile(toPos);
@ -521,12 +521,13 @@ void Game::walk(Otc::Direction direction)
(!toTile || toTile->isEmpty())) { (!toTile || toTile->isEmpty())) {
m_localPlayer->lockWalk(); m_localPlayer->lockWalk();
} else } else
return; return false;
} }
g_lua.callGlobalField("g_game", "onWalk", direction); g_lua.callGlobalField("g_game", "onWalk", direction);
forceWalk(direction); forceWalk(direction);
return true;
} }
void Game::autoWalk(const std::vector<Otc::Direction>& dirs) void Game::autoWalk(const std::vector<Otc::Direction>& dirs)
@ -778,9 +779,10 @@ void Game::attack(CreaturePtr creature)
setAttackingCreature(creature); setAttackingCreature(creature);
if(m_clientVersion >= 963) if(m_clientVersion >= 963) {
m_seq = creature->getId(); if(creature)
else m_seq = creature->getId();
} else
m_seq++; m_seq++;
m_protocolGame->sendAttack(creature ? creature->getId() : 0, m_seq); m_protocolGame->sendAttack(creature ? creature->getId() : 0, m_seq);
@ -800,9 +802,10 @@ void Game::follow(CreaturePtr creature)
setFollowingCreature(creature); setFollowingCreature(creature);
if(m_clientVersion >= 963) if(m_clientVersion >= 963) {
m_seq = creature->getId(); if(creature)
else m_seq = creature->getId();
} else
m_seq++; m_seq++;
m_protocolGame->sendFollow(creature ? creature->getId() : 0, m_seq); m_protocolGame->sendFollow(creature ? creature->getId() : 0, m_seq);

View File

@ -133,7 +133,7 @@ public:
void safeLogout(); void safeLogout();
// walk related // walk related
void walk(Otc::Direction direction); bool walk(Otc::Direction direction);
void autoWalk(const std::vector<Otc::Direction>& dirs); void autoWalk(const std::vector<Otc::Direction>& dirs);
void forceWalk(Otc::Direction direction); void forceWalk(Otc::Direction direction);
void turn(Otc::Direction direction); void turn(Otc::Direction direction);