Szerző Téma: Ló követés  (Megtekintve 186 alkalommal)

Nem elérhető Crysis2

  • Beginner
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Hozzászólások: 25
  • Segített: -4
Ló követés
« Dátum: 2019-10-06, 14:16:23 »
Sziasztok.

A ló nem követi a karaktert. (pl:/horse_summon kóddal ha előhívom a lovat a ló egy helyben áll,hiába megyek a pályán nem követ/nem teleportál.)

bool CHARACTER::Follow(LPCHARACTER pkChr, float fMinDistance)
{
if (IsPC())
{
sys_err("CHARACTER::Follow : PC cannot use this method", GetName());
return false;
}

// TRENT_MONSTER
if (IS_SET(m_pointsInstant.dwAIFlag, AIFLAG_NOMOVE))
{
if (pkChr->IsPC())
{
// If i'm in a party. I must obey party leader's AI.
if (!GetParty() || !GetParty()->GetLeader() || GetParty()->GetLeader() == this)
{
if (get_dword_time() - m_pkMobInst->m_dwLastAttackedTime >= 15000)
{
if (m_pkMobData->m_table.wAttackRange < DISTANCE_APPROX(pkChr->GetX() - GetX(), pkChr->GetY() - GetY()))
if (Return())
return true;
}
}
}
return false;
}
// END_OF_TRENT_MONSTER

long x = pkChr->GetX();
long y = pkChr->GetY();

if (pkChr->IsPC())
{
// If i'm in a party. I must obey party leader's AI.
if (!GetParty() || !GetParty()->GetLeader() || GetParty()->GetLeader() == this)
{
if (get_dword_time() - m_pkMobInst->m_dwLastAttackedTime >= 15000)
{
if (5000 < DISTANCE_APPROX(m_pkMobInst->m_posLastAttacked.x - GetX(), m_pkMobInst->m_posLastAttacked.y - GetY()))
if (Return())
return true;
}
}
}
#ifdef __BOSS_SECURITY__
if (GetMobRank() > 4)
{
if (5000 < DISTANCE_APPROX(m_pkMobInst->m_posCreate.x - GetX(), m_pkMobInst->m_posCreate.y - GetY()))
if (Return(true))
return true;
}
#endif
if (IsGuardNPC())
{
if (5000 < DISTANCE_APPROX(m_pkMobInst->m_posLastAttacked.x - GetX(), m_pkMobInst->m_posLastAttacked.y - GetY()))
if (Return())
return true;
}

#ifdef NEW_PET_SYSTEM
if (pkChr->IsState(pkChr->m_stateMove) &&
GetMobBattleType() != BATTLE_TYPE_RANGE &&
GetMobBattleType() != BATTLE_TYPE_MAGIC &&
false == IsPet() && false == IsNewPet())
#else
if (pkChr->IsState(pkChr->m_stateMove) &&
GetMobBattleType() != BATTLE_TYPE_RANGE &&
GetMobBattleType() != BATTLE_TYPE_MAGIC &&
false == IsPet())
#endif
{
float rot = pkChr->GetRotation();
float rot_delta = GetDegreeDelta(rot, GetDegreeFromPositionXY(GetX(), GetY(), pkChr->GetX(), pkChr->GetY()));

float yourSpeed = pkChr->GetMoveSpeed();
float mySpeed = GetMoveSpeed();

float fDist = DISTANCE_SQRT(x - GetX(), y - GetY());
float fFollowSpeed = mySpeed - yourSpeed * cos(rot_delta * M_PI / 180);

if (fFollowSpeed >= 0.1f)
{
float fMeetTime = fDist / fFollowSpeed;
float fYourMoveEstimateX, fYourMoveEstimateY;

if( fMeetTime * yourSpeed <= 100000.0f )
{
GetDeltaByDegree(pkChr->GetRotation(), fMeetTime * yourSpeed, &fYourMoveEstimateX, &fYourMoveEstimateY);

x += (long) fYourMoveEstimateX;
y += (long) fYourMoveEstimateY;

float fDistNew = sqrt(((double)x - GetX())*(x-GetX())+((double)y - GetY())*(y-GetY()));
if (fDist < fDistNew)
{
x = (long)(GetX() + (x - GetX()) * fDist / fDistNew);
y = (long)(GetY() + (y - GetY()) * fDist / fDistNew);
}
}
}
}

SetRotationToXY(x, y);

float fDist = DISTANCE_SQRT(x - GetX(), y - GetY());

if (fDist <= fMinDistance)
return false;

float fx, fy;

if (IsChangeAttackPosition(pkChr) && GetMobRank() < MOB_RANK_BOSS)
{
SetChangeAttackPositionTime();

int retry = 16;
int dx, dy;
int rot = (int) GetDegreeFromPositionXY(x, y, GetX(), GetY());

while (--retry)
{
if (fDist < 500.0f)
GetDeltaByDegree((rot + number(-90, 90) + number(-90, 90)) % 360, fMinDistance, &fx, &fy);
else
GetDeltaByDegree(number(0, 359), fMinDistance, &fx, &fy);

dx = x + (int) fx;
dy = y + (int) fy;

LPSECTREE tree = SECTREE_MANAGER::instance().Get(GetMapIndex(), dx, dy);

if (NULL == tree)
break;

if (0 == (tree->GetAttribute(dx, dy) & (ATTR_BLOCK | ATTR_OBJECT)))
break;
}

//sys_log(0, "근처 어딘가로 이동 %s retry %d", GetName(), retry);
if (!Goto(dx, dy))
return false;
}
else
{
float fDistToGo = fDist - fMinDistance;
GetDeltaByDegree(GetRotation(), fDistToGo, &fx, &fy);

//sys_log(0, "직선으로 이동 %s", GetName());
if (!Goto(GetX() + (int) fx, GetY() + (int) fy))
return false;
}

SendMovePacket(FUNC_WAIT, 0, 0, 0, 0);
//MonsterLog("쫓아가기; %s", pkChr->GetName());
return true;
}

hogyan lehetne ezt megoldani?