const Position& myPos = getPosition();
const Position& targetPos = attackedCreature->getPosition();
for (const spellBlock_t& spellBlock : mType->info.attackSpells) {
if (isMelee && isFleeing())
continue;
bool inRange = false;
if (attackedCreature == nullptr) {
break;
}
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 (spellBlock.isMelee) {
lastMeleeAttack = OTSYS_TIME();*/
if (isMelee || OTSYS_TIME() > (lastMeleeAttack + interval)) {
spellBlock.spell->castSpell(this, attackedCreature);
if (isMelee) {
extraMeleeAttack = false;
lastMeleeAttack = OTSYS_TIME();
}
}
}
//if (!inRange && spellBlock.isMelee) {
//melee swing out of reach
//lastMeleeAttack = 0;
if (inRange) {
outOfRange = false;
}
else if (isMelee && OTSYS_TIME() > (lastMeleeAttack + interval)) {
//melee swing out of reach
extraMeleeAttack = true;
//resetTicks = true;
//g_game.addAnimatedText(getPosition(), TEXTCOLOR_WHITE_EXP, "Extra melee");
}
}
}
//if (attacked && interval > 100) attackTicks += (interval - 100);
if (updateLook) {
updateLookDirection();
}
if (resetTicks) {
attackTicks = 0;
}
}