public void Handle(WorldClient client, MoveCharacterPacket packet) { if (_teleportationManager.IsTeleporting) { return; } if (_speedManager.Immobilize) { _logger.LogWarning("Character {id} is moving during stun. Probably cheating?", _gameSession.CharId); return; } var distance = MathExtensions.Distance(_movementManager.PosX, packet.X, _movementManager.PosZ, packet.Z); if ((distance > 6 && !_skillsManager.ChargeUsedLastTime.HasValue) || (distance > 6 && DateTime.UtcNow.Subtract(_skillsManager.ChargeUsedLastTime.Value).TotalSeconds > 2)) { _logger.LogWarning("Character {id} is moving too fast. Probably cheating?", _gameSession.CharId); return; } _movementManager.PosX = packet.X; _movementManager.PosY = packet.Y; _movementManager.PosZ = packet.Z; _movementManager.Angle = packet.Angle; _movementManager.RaisePositionChanged(); }
/// <summary> /// Generates new position for idle move. /// </summary> private void GenerateRandomIdlePosition() { float x1 = _movementManager.PosX - _idleSpeed; if (x1 < MoveArea.X1) { x1 = MoveArea.X1; } float x2 = _movementManager.PosX + _idleSpeed; if (x2 > MoveArea.X2) { x2 = MoveArea.X2; } float z1 = _movementManager.PosZ - _idleSpeed; if (z1 < MoveArea.Z1) { z1 = MoveArea.Z1; } float z2 = _movementManager.PosZ + _idleSpeed; if (z2 < MoveArea.Z2) { z2 = MoveArea.Z2; } var x = new Random().NextFloat(x1, x2); var z = new Random().NextFloat(z1, z2); Move(x, z); #if DEBUG _logger.LogDebug("AI {hashcode} walks to new position x={PosX} y={PosY} z={PosZ}.", GetHashCode(), _movementManager.PosX, _movementManager.PosY, _movementManager.PosZ); #endif _movementManager.RaisePositionChanged(); }