void Monster::doAttacking(uint32_t interval)
{
if (!attackedCreature || (isSummon() && attackedCreature == this)) {
return;
}
Player* player = attackedCreature->getPlayer();
if(player && !trySaga(player))
{
setFollowCreature(NULL);
setAttackedCreature(NULL);
searchTarget(TARGETSEARCH_NEAREST);
}
bool updateLook = true;
bool resetTicks = interval != 0;
attackTicks += interval;
const Position& myPos = getPosition();
const Position& targetPos = attackedCreature->getPosition();
for (const spellBlock_t& spellBlock : mType->attackSpells) {
bool inRange = false;
if (canUseSpell(myPos, targetPos, spellBlock, interval, inRange, resetTicks)) {
if (spellBlock.chance >= static_cast<uint32_t>(uniform_random(1, 100))) {
if (updateLook) {
updateLookDirection();
updateLook = false;
}
minCombatValue = spellBlock.minCombatValue;
maxCombatValue = spellBlock.maxCombatValue;
spellBlock.spell->castSpell(this, attackedCreature);
if (!attackedCreature) {
break;
}
if (spellBlock.isMelee) {
extraMeleeAttack = false;
}
}
}
if (!inRange && spellBlock.isMelee) {
//melee swing out of reach
extraMeleeAttack = true;
}
}
if (updateLook) {
updateLookDirection();
}
if (resetTicks) {
attackTicks = 0;
}
}