Untitled

 avatar
unknown
plain_text
18 days ago
7.1 kB
2
Indexable
// Honglim Base Grinding Script with Advanced Mob Detection and Realistic Behavior
using System;
using BDOBotAPI; // Hypothetical API namespace
using System.Windows.Forms; // For GUI integration
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.IO; // For logging errors

public class GrindHonglimBase : IGrindScript
{
    private int detectionRadius = 10;
    private string logFilePath = "bot_log.txt";

    public void Execute()
    {
        Console.WriteLine("Starting Honglim Base Grind Script with Advanced Mob Detection...");

        List<Point> grindRoute = new List<Point> // Example grind route
        {
            new Point(84, -42),
            new Point(55, -27),
            new Point(30, 14)
        };

        try
        {
            GrindLoop(grindRoute, detectionRadius);
        }
        catch (Exception ex)
        {
            LogError("An error occurred during execution: " + ex.Message);
        }
    }

    public List<Mob> GetNearbyMobs(Point playerPosition, int detectionRadius)
    {
        try
        {
            var mobs = EnemyScanner.GetNearbyEnemies();

            return mobs
                .Where(mob => mob.Health > 0)
                .Where(mob => CalculateDistance(mob.Position, playerPosition) <= detectionRadius)
                .OrderBy(mob => CalculateDistance(mob.Position, playerPosition))
                .ToList();
        }
        catch (Exception ex)
        {
            LogError("Error in GetNearbyMobs: " + ex.Message);
            return new List<Mob>();
        }
    }

    public bool IsSpotClear(Point currentSpot, int detectionRadius)
    {
        try
        {
            var mobs = GetNearbyMobs(currentSpot, detectionRadius);

            if (mobs.Count == 0)
            {
                Thread.Sleep(1000); // Add a slight delay for human-like behavior
                mobs = GetNearbyMobs(currentSpot, detectionRadius);
                return mobs.Count == 0;
            }

            return false;
        }
        catch (Exception ex)
        {
            LogError("Error in IsSpotClear: " + ex.Message);
            return true; // Assume spot is clear to avoid infinite loops
        }
    }

    public void EngageEnemiesAtSpot(Point spot, int detectionRadius)
    {
        try
        {
            Console.WriteLine($"Engaging mobs at spot: X={spot.X}, Y={spot.Y}");

            while (!IsSpotClear(spot, detectionRadius))
            {
                var mobs = GetNearbyMobs(spot, detectionRadius);

                foreach (var mob in mobs)
                {
                    Console.WriteLine($"Engaging mob ID: {mob.ID} at X={mob.Position.X}, Y={mob.Position.Y}");

                    SmoothAim(mob.Position);
                    SimulateReactionTime();

                    UseSkill("Lightning Chain");
                    UseSkill("Voltaic Pulse");

                    if (new Random().Next(0, 5) == 0) // 20% chance to reposition
                    {
                        RepositionDuringCombat();
                    }

                    Thread.Sleep(500); // Adjust delay for skill timing
                }
            }

            Console.WriteLine("Spot cleared of enemies.");
        }
        catch (Exception ex)
        {
            LogError("Error in EngageEnemiesAtSpot: " + ex.Message);
        }
    }

    public void GrindLoop(List<Point> grindRoute, int detectionRadius)
    {
        try
        {
            foreach (var spot in grindRoute)
            {
                Console.WriteLine($"Moving to spot: X={spot.X}, Y={spot.Y}");
                Navigation.MoveTo(spot);

                if (!IsSpotClear(spot, detectionRadius))
                {
                    EngageEnemiesAtSpot(spot, detectionRadius);
                }
                else
                {
                    Console.WriteLine("Spot is clear. Moving to the next spot...");
                }
            }

            Console.WriteLine("Route complete.");
        }
        catch (Exception ex)
        {
            LogError("Error in GrindLoop: " + ex.Message);
        }
    }

    private void SmoothAim(Point targetPosition)
    {
        try
        {
            Point currentPosition = GetPlayerPosition();
            while (CalculateDistance(currentPosition, targetPosition) > 1)
            {
                int stepX = (targetPosition.X - currentPosition.X) / 10;
                int stepY = (targetPosition.Y - currentPosition.Y) / 10;

                currentPosition.X += stepX;
                currentPosition.Y += stepY;

                Thread.Sleep(50);
            }
            Console.WriteLine("Aim adjusted to target.");
        }
        catch (Exception ex)
        {
            LogError("Error in SmoothAim: " + ex.Message);
        }
    }

    private void SimulateReactionTime()
    {
        try
        {
            Random random = new Random();
            int delay = random.Next(200, 500); // 200-500ms delay
            Thread.Sleep(delay);
            Console.WriteLine($"Reaction time: {delay}ms");
        }
        catch (Exception ex)
        {
            LogError("Error in SimulateReactionTime: " + ex.Message);
        }
    }

    private void RepositionDuringCombat()
    {
        try
        {
            Random random = new Random();
            int offsetX = random.Next(-10, 10);
            int offsetY = random.Next(-10, 10);
            Point newPosition = new Point(GetPlayerPosition().X + offsetX, GetPlayerPosition().Y + offsetY);

            Console.WriteLine($"Repositioning to: X={newPosition.X}, Y={newPosition.Y}");
            Navigation.MoveTo(newPosition);
        }
        catch (Exception ex)
        {
            LogError("Error in RepositionDuringCombat: " + ex.Message);
        }
    }

    private Point GetPlayerPosition()
    {
        try
        {
            return GetterSetter.GetField<Point>("PlayerPosition");
        }
        catch (Exception ex)
        {
            LogError("Error in GetPlayerPosition: " + ex.Message);
            return new Point(0, 0); // Return a default position
        }
    }

    private int CalculateDistance(Point a, Point b)
    {
        return (int)Math.Sqrt(Math.Pow(a.X - b.X, 2) + Math.Pow(a.Y - b.Y, 2));
    }

    private void UseSkill(string skillName)
    {
        try
        {
            Console.WriteLine($"Using skill: {skillName}");
            Skills.Cast(skillName);
        }
        catch (Exception ex)
        {
            LogError("Error in UseSkill: " + ex.Message);
        }
    }

    private void LogError(string message)
    {
        try
        {
            File.AppendAllText(logFilePath, $"{DateTime.Now}: {message}{Environment.NewLine}");
        }
        catch
        {
            // If logging fails, avoid crashing the bot
            Console.WriteLine("Failed to write to log file.");
        }
    }
}

public class Mob
{
    public int ID { get; set; }
    public Point Position { get; set; }
    public int Health { get; set; }
}
Leave a Comment