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)
{
if(isAttacking() && (seq == 0 || m_seq == seq))
setAttackingCreature(nullptr);
cancelAttack();
}
void Game::processWalkCancel(Otc::Direction direction)
@ -737,33 +737,38 @@ void Game::refreshContainer()
m_protocolGame->sendRefreshContainer();
}
void Game::attack(const CreaturePtr& creature)
void Game::attack(CreaturePtr creature)
{
if(!canPerformGameAction() || creature == m_localPlayer)
return;
if(creature && creature == m_attackingCreature) {
cancelAttack();
return;
}
// cancel when attacking again
if(creature && creature == m_attackingCreature)
creature = nullptr;
if(creature && isFollowing())
cancelFollow();
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;
// cancel when following again
if(creature && creature == m_followingCreature)
creature = nullptr;
if(creature && isAttacking())
cancelAttack();
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()
@ -771,11 +776,6 @@ void Game::cancelAttackAndFollow()
if(!canPerformGameAction())
return;
if(isAttacking())
setAttackingCreature(nullptr);
if(isFollowing())
setFollowingCreature(nullptr);
m_protocolGame->sendCancelAttackAndFollow();
}

View File

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