Ok so i've implemented the wall detection using NStcData.NOS files and it work fine
That's what i've done
Code:
public async Task Walk(Vector2D target)
{
var distance = Position.Distance(target);
bool positiveX = target.X > Position.X;
bool positiveY = target.Y > Position.Y;
for (var i = 0; i < distance.X; i++)
{
var position = Position.Clone();
position.X = (positiveX ? 1 : -1) + position.X;
if (Map.IsWalkable(position))
{
await _clientSession.SendPacket(new WalkPacket
{
Position = position,
Speed = Speed
});
Position = position;
await Task.Delay(200);
}
}
for (var i = 0; i < distance.Y; i++)
{
var position = Position.Clone();
position.Y = (positiveY ? 1 : -1) + position.Y;
if (Map.IsWalkable(position))
{
await _clientSession.SendPacket(new WalkPacket
{
Position = position,
Speed = Speed
});
Position = position;
await Task.Delay(200);
}
}
}
but i'm still stuck on a wait to make the movement more realistic (like moving on X/Y axis in same time
Ok i've made something else and everything looks fine
Code:
public async Task<bool> Walk(Vector2D destination)
{
if (!Map.IsWalkable(destination)) return false;
bool positiveX = destination.X > Position.X;
bool positiveY = destination.Y > Position.Y;
var blocked = false;
while(!Position.Equals(destination) && !blocked)
{
var position = Position.Clone();
var distance = position.Distance(destination);
int stepX = distance.X >= 5 ? 5 : distance.X;
int stepY = distance.Y >= 5 ? 5 : distance.Y;
position.X = (positiveX ? 1 : -1) * stepX + position.X;
position.Y = (positiveY ? 1 : -1) * stepY + position.Y;
if (Map.IsWalkable(position))
{
await _clientSession.SendPacket(new WalkPacket
{
Position = position,
Speed = Speed
});
await Task.Delay((stepX + stepY) * (1000 / Speed));
Position = position;
}
else
{
blocked = true;
}
}
return !blocked;
}
I've one last question what's the third parameter of the Walk packet ?
Actually i'm just setting it to 0 but my character looks like i'm lagging (running faster some time) it's because of this parameter ?
I've looked with packet logger but i can't find something logical about this parameter if someone can tell me in which case the value is 1 or 0 thanks alot