Register for your free account! | Forgot your password?

Go Back   elitepvpers > MMORPGs > Conquer Online 2 > CO2 Private Server
You last visited: Today at 21:22

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Unfinished Basic AutoHunting?

Discussion on Unfinished Basic AutoHunting? within the CO2 Private Server forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Nov 2020
Posts: 64
Received Thanks: 7
Unfinished Basic AutoHunting?

Here you go guys, it was a simple system i was attempting to make. But i couldent figure out the Dcells and So it would walk over parts of the map it shouldn't. Maybe one of you guys could do something with it. enjoy lol.
Code:
using COServer.Structures;
using System;
using System.Collections.Generic;

namespace COServer.Game
{
    public class AutoHuntSystem
    {
        private Character Player;
        private Mob CurrentMob;

        public AutoHuntSystem(Character player, Mob mob)
        {
            Player = player;
            CurrentMob = mob;
        }

        // Your other class members go here

        public void AutoHunt()
        {
            while (true) // You may want to implement some exit condition
            {
                // Detect nearby mobs
                List<Mob> nearbyMobs = DetectNearbyMobs();

                // Attack mobs if found
                if (nearbyMobs.Count > 0)
                {
                    Mob targetMob = SelectTargetMob(nearbyMobs);
                    ApproachAndAttackMob(targetMob);
                }

                // Implement other actions as needed
            }
        }

        private List<Mob> DetectNearbyMobs()
        {
            List<Mob> detectedMobs = new List<Mob>();

            // Iterate through mobs in the same map and add them to detectedMobs if they meet the criteria
            foreach (Mob mob in World.H_Mobs[CurrentMob.Loc.Map].Values)
            {
                if (mob != CurrentMob && mob.Type == MobBehaveour.HuntPlayers && mob.Alive)
                {
                    float distance = MyMath.PointDistance(Player.Loc.X, Player.Loc.Y, mob.Loc.X, mob.Loc.Y);
                    if (distance <= 24)
                    {
                        detectedMobs.Add(mob);
                    }
                }
            }

            return detectedMobs;
        }

        // Implement SelectTargetMob, IsInRange, CalculateDirection, MoveTowards, and AttackMob methods here as previously defined in your code.
        // You may also want to consider adding additional properties and methods for improved readability and maintainability.

        public Mob SelectTargetMob(List<Mob> nearbyMobs)
        {
            Mob nearestMob = null;
            float nearestDistance = float.MaxValue;

            foreach (Mob mob in nearbyMobs)
            {
                // Calculate the distance from the player to the current mob
                float distance = MyMath.PointDistance(Player.Loc.X, Player.Loc.Y, mob.Loc.X, mob.Loc.Y);

                // Check if the current mob is closer than the previously selected nearest mob
                if (distance < nearestDistance)
                {
                    nearestDistance = distance;
                    nearestMob = mob;
                }
            }

            return nearestMob;
        }

        public void ApproachAndAttackMob(Mob mob)
        {
            if (mob != null)
            {
                if (IsInRange(mob))
                {
                    // Attack the target mob
                    AttackMob(mob);
                }
                else
                {
                    // Calculate direction to move towards the target mob
                    byte direction = CalculateDirection(mob);

                    // Move towards the target mob while avoiding obstacles
                    MoveTowards(mob, direction);
                }
            }
        }

        public bool IsInRange(Mob mob)
        {
            // Implement logic to check if the mob is within attack range
            // You can use a predefined attack range constant or calculate it dynamically
            // For example, you can check the distance between the player and the mob
            float distance = MyMath.PointDistance(Player.Loc.X, Player.Loc.Y, mob.Loc.X, mob.Loc.Y);
            return distance <= Player.Loc.X;
        }

        public byte CalculateDirection(Mob mob)
        {
            // Calculate the direction vector from the player to the target mob
            Vector2 directionVector = new Vector2((ushort)(mob.Loc.X - Player.Loc.X), (ushort)(mob.Loc.Y - Player.Loc.Y));

            // Calculate the angle in radians from the direction vector
            float angle = (float)Math.Atan2(directionVector.Y, directionVector.X);

            // Convert the angle to degrees
            float degrees = (float)((angle * 180f) / Math.PI);

            // Ensure the degrees value is positive
            if (degrees < 0)
            {
                degrees += 360f;
            }

            // Map the degrees value to a byte representing a direction
            byte direction = MapDegreesToDirection(degrees);

            return direction;
        }

        // Helper function to map degrees to a direction byte
        private byte MapDegreesToDirection(float degrees)
        {
            // Define direction ranges (e.g., 45 degrees for each direction)
            float directionRange = 360f / 8;

            // Calculate the direction based on the degrees value
            if (degrees >= 0 && degrees < directionRange)
            {
                return 0; // East
            }
            else if (degrees >= directionRange && degrees < 2 * directionRange)
            {
                return 1; // Southeast
            }
            else if (degrees >= 2 * directionRange && degrees < 3 * directionRange)
            {
                return 2; // South
            }
            else if (degrees >= 3 * directionRange && degrees < 4 * directionRange)
            {
                return 3; // Southwest
            }
            else if (degrees >= 4 * directionRange && degrees < 5 * directionRange)
            {
                return 4; // West
            }
            else if (degrees >= 5 * directionRange && degrees < 6 * directionRange)
            {
                return 5; // Northwest
            }
            else if (degrees >= 6 * directionRange && degrees < 7 * directionRange)
            {
                return 6; // North
            }
            else
            {
                return 7; // Northeast
            }
        }

        public void MoveTowards(Mob mob, byte direction)
        {
            // Implement logic to move the character towards the target mob
            // while avoiding obstacles
            // You can use a pathfinding algorithm or simple movement logic here

            // Example: Move the player one step in the specified direction
            switch (direction)
            {
                case 0: // East
                    Player.Loc.X += 1;
                    break;
                case 1: // Southeast
                    Player.Loc.X += 1;
                    Player.Loc.Y += 1;
                    break;
                case 2: // South
                    Player.Loc.Y += 1;
                    break;
                case 3: // Southwest
                    Player.Loc.X -= 1;
                    Player.Loc.Y += 1;
                    break;
                case 4: // West
                    Player.Loc.X -= 1;
                    break;
                case 5: // Northwest
                    Player.Loc.X -= 1;
                    Player.Loc.Y -= 1;
                    break;
                case 6: // North
                    Player.Loc.Y -= 1;
                    break;
                case 7: // Northeast
                    Player.Loc.X += 1;
                    Player.Loc.Y -= 1;
                    break;
                default:
                    break;
            }
        }


        public void AttackMob(Mob mob)
        {
            // Check if the target mob is valid and alive
            if (mob != null && mob.Alive)
            {
                // Implement your attack logic here
                // Calculate the damage to deal to the mob and any other attack actions

                // For example, you can calculate damage based on the player's stats
                uint damage = CalculateDamage(Player, mob);

                // Apply the damage to the mob by passing it by reference with 'ref'
                mob.TakeAttack(Player, ref damage, AttackType.Melee, true);

                // Optionally, check if the mob is defeated and handle the aftermath
                if (!mob.Alive)
                {
                    // Handle the aftermath of defeating the mob, such as gaining experience or loot
                }
            }
        }

        // Implement a method to calculate the damage to be dealt to the target mob.
        private uint CalculateDamage(Character player, Mob mob)
        {
            // Implement your logic to calculate the damage based on the player's attributes,
            // equipment, and any other relevant factors.
            // You can customize this calculation based on your game's combat mechanics.

            // Example: Calculate damage as a random value between MinDamage and MaxDamage
            uint damage = 100;

            return damage;
        }

        // Top-level statements or other classes can go here
    }
}
TheFadedOne is offline  
Old 06/07/2025, 10:25   #2
 
elite*gold: 0
Join Date: Jan 2025
Posts: 1
Received Thanks: 0
you can't do it with AI anyway lol
dohteMxx is offline  
Reply


Similar Threads Similar Threads
How AutoHunting is working
02/07/2018 - Conquer Online 2 - 9 Replies
i want to know how autohunt detect refined item and collect when its chosen to collect +refined items if it gets item quality from itemtype so if i change the id of specific normal item to other id of refined item so the autohunting will collect this normal item as its refined ?? :mofo: any help
Superman Autohunting?!?!?!?
03/26/2014 - Conquer Online 2 - 7 Replies
I've been seeing it everywhere. they're all Egyptian so they can't respond to me when I ask where to get it or how it works or whatever. Can anyone help me with what's going on? How can i do it? Thank you if you can. If not, oh well lol
Autohunting, and auto plvling bots?
08/11/2009 - Conquer Online 2 - 5 Replies
Does anyone have a Autohunting or autoplvling bot? E.g Your archer would just hop around Bird Island, shooting and you will have noobs jumping after it? and for autohunt like a program where you make a radius where your character would jump around, Auto pick up items drop normal items and keep Quality and +1 items, Meteors, Dragonballs anything worth money. And it would AutoPot, Auto Disconnect when attacked, would go back to city to buy arrows and pots and warehouses the items? If anyone could...
where i can find autohunting bot
06/11/2009 - CO2 Programming - 3 Replies
hi all plz i want best autohunting bot hunt R - U - E - S item from the ground



All times are GMT +1. The time now is 21:24.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.