void Player::doAttacking(uint32_t interval)
{
if(lastAttack == 0){
// - 1 to compensate for timer resolution etc.
lastAttack = OTSYS_TIME() - getAttackSpeed() - 1;
}
// Can't attack while pacified
if(hasCondition(CONDITION_PACIFIED))
{
return;
}
if((OTSYS_TIME() - lastAttack) >= getAttackSpeed() ){
Item* tool = getWeapon();
bool result = false;
const Weapon* weapon = g_weapons->getWeapon(tool);
if(weapon){
if(!weapon->interruptSwing()){
result = weapon->useWeapon(this, tool, attackedCreature);
}
else if(!canDoAction()){
uint32_t delay = getNextActionTime();
SchedulerTask* task = createSchedulerTask(delay, boost::bind(&Game::checkCreatureAttack,
&g_game, getID()));
setNextActionTask(task);
}
else {
// If the player is not exhausted OR if the player's weapon
// does not have hasExhaust, use the weapon.
if(!hasCondition(CONDITION_EXHAUST_COMBAT))
{
result = weapon->useWeapon(this, tool, attackedCreature);
}
}
}
else{
result = Weapon::useFist(this, attackedCreature);
}
if(result){
lastAttack = OTSYS_TIME();
}
}
}