Code:
{
if (!IsRunning)
return;
if (CLooter::instance()->block())
return;
// Seek the nearest role which is a monster.
int px, py;
CO::CHero::instance()->getCoords(&px, &py);
CO::CRole* nearRole = NULL;
int minDist = INT_MAX;
for (int i = 0; i < CO::CMobList::instance()->size(); ++i)
{
CO::CRole* role = (*CO::CMobList::instance())[i];
if (role == NULL)
break;
if (role->alive() && !(role->isPlayer()))
{
int rx, ry;
role->getCoords(&rx, &ry);
int dx = rx - px;
int dy = ry - py;
int dist = dx*dx + dy*dy;
if (dist < minDist)
{
minDist = dist;
nearRole = role;
}
}
}
if (nearRole != NULL)
{
//if (!(CPathRecorder::instance()->isBlocked()))
// CPathRecorder::instance()->block();
if (minDist < MinAttackDistance*MinAttackDistance)
{
CO::CHero::instance()->melee(nearRole);
}
else
{
int x, y;
nearRole->getCoords(&x, &y);
++x; ++y;
int dx = x - px;
int dy = y - py;
if (dx*dx+dy*dy>=10*10)
{
float a = 10.0 / sqrt(dx*dx+dy*dy);
dx = (int)(a * (float)dx);
dy = (int)(a * (float)dy);
}
x = px + dx;
y = py + dy;
CO::Functions::findClearGround(&x, &y);
CO::CHero::instance()->jump(x, y);
}
}
else
{
//if (CPathRecorder::instance()->isBlocked())
// CPathRecorder::instance()->unblock();
}
}






