Code:
void Player::doAttacking(uint32_t)
{
if (lastAttack == 0) {
lastAttack = OTSYS_TIME() - getAttackSpeed() - 1;
}
if (hasCondition(CONDITION_PACIFIED)) {
return;
}
You can ignore the above code, it is working as intended.
It sets your defaults if you have never attacked before, and cancels your attack if you are pacified.
Code:
if ((OTSYS_TIME() - lastAttack) >= getAttackSpeed()) {
bool result = false;
Item* tool = getWeapon();
const Weapon* weapon = g_weapons->getWeapon(tool);
if (weapon) {
This code checks if you can attack, then grabs your weapon (to make sure you aren't using fist).
This is working as intended, so we can ignore it as well.
Code:
if (!weapon->interruptSwing()) {
result = weapon->useWeapon(this, tool, attackedCreature);
This code checks if your weapon has interruptSwing. Almost no one uses this, I think it is off by default. (Basically says you can "swing" your weapon and miss, resetting your attackspeed if you are far away from your target)
This is working as intended, so we can ignore it as well.
Code:
} else if (!canDoAction()) {
uint32_t delay = getNextActionTime();
SchedulerTask* task = createSchedulerTask(delay, std::bind(&Game::checkCreatureAttack,
&g_game, getID()));
setNextActionTask(task);
This code can be optimized a bit, to make things easier to see what is going on, BUT I think this is also working as intended.
This checks if you can attack, if you cannot it tries again at "getNextActionTime()" (So it waits a small amount of time before attempting to attack again if the attack fails for some reason)
Technically we can skip this too.
Code:
} else {
result = weapon->useWeapon(this, tool, attackedCreature);
}
This code does the attack if you have a weapon, working as intended so we can skip it.
Code:
} else {
result = Weapon::useFist(this, attackedCreature);
}
This code does the attack if you do not have a weapon (using fist), working as intended so we can skip it.