Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Monster Look Direction Behavior #4785

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 11 additions & 10 deletions src/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,11 @@ void Monster::onThink(uint32_t interval)
} else {
updateIdleStatus();

// Ensure monsters update look direction.
if (!isFleeing() && attackedCreature) {
updateLookDirection();
}

if (!isIdle) {
addEventWalk();

Expand Down Expand Up @@ -790,7 +795,6 @@ void Monster::doAttacking(uint32_t interval)
return;
}

bool lookUpdated = false;
bool resetTicks = interval != 0;
attackTicks += interval;

Expand All @@ -806,9 +810,11 @@ void Monster::doAttacking(uint32_t interval)

if (canUseSpell(myPos, targetPos, spellBlock, interval, inRange, resetTicks)) {
if (spellBlock.chance >= static_cast<uint32_t>(uniform_random(1, 100))) {
if (!lookUpdated) {
if ((isFleeing() ||
mType->info.targetDistance > (myPos.getDistanceX(targetPos) + myPos.getDistanceY(targetPos))) &&
inRange) {
updateLookDirection();
lookUpdated = true;
lastStep = OTSYS_TIME() - 200;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This made the sheep extremely slow 🐢

}

minCombatValue = spellBlock.minCombatValue;
Expand All @@ -827,11 +833,6 @@ void Monster::doAttacking(uint32_t interval)
}
}

// ensure ranged creatures turn to player
if (!lookUpdated && lastMeleeAttack == 0) {
updateLookDirection();
}

if (resetTicks) {
attackTicks = 0;
}
Expand Down Expand Up @@ -1905,8 +1906,8 @@ void Monster::updateLookDirection()
if (attackedCreature) {
const Position& pos = getPosition();
const Position& attackedCreaturePos = attackedCreature->getPosition();
int32_t offsetx = pos.getOffsetX(attackedCreaturePos);
int32_t offsety = pos.getOffsetY(attackedCreaturePos);
int32_t offsetx = attackedCreaturePos.getOffsetX(pos);
int32_t offsety = attackedCreaturePos.getOffsetY(pos);

int32_t dx = std::abs(offsetx);
int32_t dy = std::abs(offsety);
Expand Down
Loading