Adjustments in attack/follow algorithm

This commit is contained in:
Eduardo Bart 2012-08-17 14:43:12 -03:00
parent 42ccff8596
commit a91b7ed6be
2 changed files with 17 additions and 17 deletions

View File

@ -385,7 +385,7 @@ void Game::processQuestLine(int questId, const std::vector<std::tuple<std::strin
void Game::processAttackCancel(uint seq) void Game::processAttackCancel(uint seq)
{ {
if(isAttacking() && (seq == 0 || m_seq == seq)) if(isAttacking() && (seq == 0 || m_seq == seq))
setAttackingCreature(nullptr); cancelAttack();
} }
void Game::processWalkCancel(Otc::Direction direction) void Game::processWalkCancel(Otc::Direction direction)
@ -737,33 +737,38 @@ void Game::refreshContainer()
m_protocolGame->sendRefreshContainer(); m_protocolGame->sendRefreshContainer();
} }
void Game::attack(const CreaturePtr& creature) void Game::attack(CreaturePtr creature)
{ {
if(!canPerformGameAction() || creature == m_localPlayer) if(!canPerformGameAction() || creature == m_localPlayer)
return; return;
if(creature && creature == m_attackingCreature) { // cancel when attacking again
cancelAttack(); if(creature && creature == m_attackingCreature)
return; creature = nullptr;
}
if(creature && isFollowing()) if(creature && isFollowing())
cancelFollow(); cancelFollow();
setAttackingCreature(creature); setAttackingCreature(creature);
m_protocolGame->sendAttack(creature ? creature->getId() : 0, ++m_seq); m_seq++;
m_protocolGame->sendAttack(creature ? creature->getId() : 0, m_seq);
} }
void Game::follow(const CreaturePtr& creature) void Game::follow(CreaturePtr creature)
{ {
if(!canPerformGameAction() || creature == m_localPlayer || creature == m_followingCreature) if(!canPerformGameAction() || creature == m_localPlayer)
return; return;
// cancel when following again
if(creature && creature == m_followingCreature)
creature = nullptr;
if(creature && isAttacking()) if(creature && isAttacking())
cancelAttack(); cancelAttack();
setFollowingCreature(creature); setFollowingCreature(creature);
m_protocolGame->sendFollow(creature ? creature->getId() : 0, ++m_seq); m_seq++;
m_protocolGame->sendFollow(creature ? creature->getId() : 0, m_seq);
} }
void Game::cancelAttackAndFollow() void Game::cancelAttackAndFollow()
@ -771,11 +776,6 @@ void Game::cancelAttackAndFollow()
if(!canPerformGameAction()) if(!canPerformGameAction())
return; return;
if(isAttacking())
setAttackingCreature(nullptr);
if(isFollowing())
setFollowingCreature(nullptr);
m_protocolGame->sendCancelAttackAndFollow(); m_protocolGame->sendCancelAttackAndFollow();
} }

View File

@ -156,9 +156,9 @@ public:
void refreshContainer(); void refreshContainer();
// attack/follow related // attack/follow related
void attack(const CreaturePtr& creature); void attack(CreaturePtr creature);
void cancelAttack() { attack(nullptr); } void cancelAttack() { attack(nullptr); }
void follow(const CreaturePtr& creature); void follow(CreaturePtr creature);
void cancelFollow() { follow(nullptr); } void cancelFollow() { follow(nullptr); }
void cancelAttackAndFollow(); void cancelAttackAndFollow();