Author Topic: [V6, C#] oEggs - Orich's Medusa Egg Farmer  (Read 19814 times)

0 Members and 1 Guest are viewing this topic.

Offline unisharp

  • Elite
  • ***
  • *
  • Posts: 196
  • Activity:
    0%
  • Reputation Power: 4
  • unisharp has no influence.
  • Gender: Male
  • Respect: +40
  • Referrals: 0
    • View Profile
Re: [V6, C#] oEggs - Orich's Medusa Egg Farmer
« Reply #15 on: May 06, 2015, 03:22:15 AM »
0
oEggs - Revisited v0.1 Alpha

Updated and working.  Changed it around a bit, there's two parts to this:  The routine of using a flute targeting a snake and then a nest, and then a separate thread running a function that searches for eggs and picks them up.

Pretty quick and dirty I took out most of the Journal checking since we no longer need to verify whether or not a snake was successful.

Code: [Select]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

using ScriptAPI;
using ScriptDotNet2;


/*
This script is extremely sloppy, without a plethora of sanity checks, and was written between 3:00am and 3:41am
 
*/

namespace oEggs
{
    class Program
    {
        public static ushort[] SnakeTypes = new ushort[] { 52, 93, 21 };

        public static List<Item> Snakes = new List<Item>();
        public static List<Item> Nests = new List<Item>();
        public static List<Item> Flutes = new List<Item>();

        private static readonly Object locker = new Object();

        #region Methods
        static void ErrorExit(string ErrorText)
        {
            Console.WriteLine(ErrorText);
            Console.Write("Press any key to suicide.");
            Console.ReadKey(false);
            Environment.Exit(0);
        }

        /// <summary>
        /// Method for posting messages to the console
        /// with a timestamp
        /// </summary>
        /// <param name="message">string: message to send to the console</param>
        /// <param name="args">(optional)object[]: additional arguments</param>
        public static void ConsoleMessage(string message, params object[] args)
        {
            Console.Write("[{0}] ", DateTime.Now.ToString("mm:ss"));
            Console.WriteLine(message, args);
        }

        /// <summary>
        /// Method for posting messages to the console
        /// with a timestamp and optional color
        /// </summary>
        /// <param name="message">string: message to send to the console</param>
        /// <param name="color">(optional)enum ConsoleColor: the color you want the message to be</param>
        /// <param name="args">(optional)object[]: additional arguments</param>
        public static void ConsoleMessage(string message, ConsoleColor color = ConsoleColor.White, params object[] args)
        {
            Console.Write("[{0}] ", DateTime.Now.ToString("mm:ss"));
            Console.ForegroundColor = color;
            Console.WriteLine(message, args);
            Console.ResetColor();
        }
        #endregion

        static void Main(string[] args)
        {

            /*while (true)
            {
                Item Result = Target.RequestTarget();

                Console.WriteLine(Result.Type);
            }*/

            #region Events
            //Stealth.Default.Buff_DebuffSystem += onBuff;
            //Stealth.Default.UnicodeSpeech += onSpeech;
            #endregion

            Thread EggFinderThread = new Thread(FindEggs);
            EggFinderThread.Start();

            ConsoleMessage("Waiting for connection...");
            while (!Profile.IsConnected) ;
            ConsoleMessage("Connection detected.  Welcome {0}!", Self.Name);

            FindFlutes();
            if (Flutes.Count < 0)
                ErrorExit("Not enough snake charmer flutes.  Bye.");

            ConsoleMessage("Starting egg farm...");

            while (Profile.IsConnected)
            {
                MainRoutine();
            }


        }

        private static void MainRoutine()
        {
            DateTime thisTime = DateTime.Now;

            Stealth.Default.ClearJournal();

            lock (locker)
            {
                #region Search
            Search:
                FindSnakes();
                ConsoleMessage("Found {0} snakes",
                    ConsoleColor.DarkYellow, Snakes.Count);
                if (Snakes.Count == 0)
                {
                    Thread.Sleep(5000);
                    goto Search;
                }

                FindNests();
                ConsoleMessage("Found {0} nests",
                    ConsoleColor.DarkYellow, Nests.Count);
                if (Nests.Count == 0)
                {
                    Thread.Sleep(5000);
                    goto Search;
                }

                FindFlutes();
                ConsoleMessage("Found {0} flutes",
                    ConsoleColor.DarkYellow, Flutes.Count);
                if (Flutes.Count < 1)
                    ErrorExit("Ran out of flutes.");
                #endregion

                Item Flute = Flutes[0];

                for (int i = 0; i < Snakes.Count; i++)
                {
                    if (i == 3)
                        break;

                    ConsoleMessage("Attempting flute process...",
                        ConsoleColor.DarkYellow);
                    Stealth.Default.CancelWaitTarget();

                    while (true)
                    {
                        thisTime = DateTime.Now;
                        Flute.Use();
                        if (!Stealth.Default.WaitJournalLine(thisTime, "You must wait a moment for it to recharge.", 750))
                            break;

                        ConsoleMessage("Flute waiting to recharge.  Trying again in 1.5s.",
                            ConsoleColor.DarkRed);
                        Script.Wait(1500);
                    }

                    Stealth.Default.WaitTargetObject(Snakes[i].ID);
                    Script.Wait(1000);
                    Stealth.Default.WaitTargetObject(Nests[0].ID);

                    Script.Wait(10000);
                }
            }
        }

        static void FindSnakes()
        {
            Find.FindDistance = 10;
            Snakes = Find.FindItems(52);
            Snakes.AddRange(Find.FindItems(21));
            Snakes.AddRange(Find.FindItems(93));
            Snakes.OrderBy(x => x.Distance).ToList();
        }

        static void FindFlutes()
        {
            Flutes = Find.FindItems(0x2807, Self.Backpack.ID);
        }

        static void FindNests()
        {
            Find.FindDistance = 10;
            Nests = Find.FindItems(8755);
            Nests.OrderBy(n => n.Distance).ToList();
        }

        static void FindEggs()
        {
            while (true)
            {
                lock (locker)
                {
                    List<Item> Eggs = Find.FindItems(16831);
                    if (Eggs.Count > 0)
                    {
                        for (int i = 0; i < Eggs.Count; i++)
                        {
                            while (Self.X != Eggs[i].X && Self.Y != Eggs[i].Y)
                            {
                                Script.Wait(1000);
                                Stealth.Default.MoveXY((ushort)Eggs[i].X, (ushort)Eggs[0].Y, false, 0, false);
                                if (Self.X != Eggs[i].X && Self.Y != Eggs[i].Y)
                                    break;
                            }
                            Console.WriteLine("Taking the egg.");
                            Stealth.Default.DragItem(Eggs[i].ID, 1);
                            Script.Wait(1500);
                            Stealth.Default.DropHere(Self.Backpack.ID);
                        }
                    }
                }
                Script.Wait(10000);
            }
        }
    }
}

I had a hard time deciding on distance checks, because of the terrain.  The vertical changing ground tiles are a pain in the arse, you'll be 5 tiles from something but you still can't either see it or reach it.  For this reason I suggest trying out different spots if you're having difficulty.
« Last Edit: May 06, 2015, 04:04:01 AM by sibble »

Offline unisharp

  • Elite
  • ***
  • *
  • Posts: 196
  • Activity:
    0%
  • Reputation Power: 4
  • unisharp has no influence.
  • Gender: Male
  • Respect: +40
  • Referrals: 0
    • View Profile
Re: [V6, C#] oEggs - Orich's Medusa Egg Farmer
« Reply #16 on: May 06, 2015, 03:32:48 AM »
0
One more thing, for some reason when it checks for snakes it always comes up with 0 the first time.  It checks for new snakes and new nests every 5 seconds if it couldn't find any.  Just let it run, it'll find em!

I watched it successfully pick eggs up, then last night I watched it walk to an Egg and not pick it up.  More testing is needed.

EDIT: A couple other notes lol...

After searching for snakes... say it finds 20 snakes on screen.  It'll loop through the first 3 it finds and then re-search and start over.  I did it this way because if it did find 20 snakes, when it gets to say 15, the snake that it's now targeting will most likely be inaccessible (off screen.)  This way after it gets to the 3rd snake, the 1st one should be finished searching and able to search again.
« Last Edit: May 06, 2015, 03:35:43 AM by sibble »

Offline unisharp

  • Elite
  • ***
  • *
  • Posts: 196
  • Activity:
    0%
  • Reputation Power: 4
  • unisharp has no influence.
  • Gender: Male
  • Respect: +40
  • Referrals: 0
    • View Profile
Re: [V6, C#] oEggs - Orich's Medusa Egg Farmer
« Reply #17 on: May 06, 2015, 04:37:02 AM »
0
One more update
Rev0.2a

Changed from using Drag/Drop item to MoveItem.

Code: [Select]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

using ScriptAPI;
using ScriptDotNet2;


/*
This script is extremely sloppy, without a plethora of sanity checks, and was written between 3:00am and 3:41am
 
*/

namespace oEggs
{
    class Program
    {
        public static ushort[] SnakeTypes = new ushort[] { 52, 93, 21 };

        public static List<Item> Snakes = new List<Item>();
        public static List<Item> Nests = new List<Item>();
        public static List<Item> Flutes = new List<Item>();

        private static readonly Object locker = new Object();

        #region Methods
        static void ErrorExit(string ErrorText)
        {
            Console.WriteLine(ErrorText);
            Console.Write("Press any key to suicide.");
            Console.ReadKey(false);
            Environment.Exit(0);
        }

        /// <summary>
        /// Method for posting messages to the console
        /// with a timestamp
        /// </summary>
        /// <param name="message">string: message to send to the console</param>
        /// <param name="args">(optional)object[]: additional arguments</param>
        public static void ConsoleMessage(string message, params object[] args)
        {
            Console.Write("[{0}] ", DateTime.Now.ToString("mm:ss"));
            Console.WriteLine(message, args);
        }

        /// <summary>
        /// Method for posting messages to the console
        /// with a timestamp and optional color
        /// </summary>
        /// <param name="message">string: message to send to the console</param>
        /// <param name="color">(optional)enum ConsoleColor: the color you want the message to be</param>
        /// <param name="args">(optional)object[]: additional arguments</param>
        public static void ConsoleMessage(string message, ConsoleColor color = ConsoleColor.White, params object[] args)
        {
            Console.Write("[{0}] ", DateTime.Now.ToString("mm:ss"));
            Console.ForegroundColor = color;
            Console.WriteLine(message, args);
            Console.ResetColor();
        }
        #endregion

        static void Main(string[] args)
        {

            /*while (true)
            {
                Item Result = Target.RequestTarget();

                Console.WriteLine(Result.Type);
            }*/

            #region Events
            //Stealth.Default.Buff_DebuffSystem += onBuff;
            //Stealth.Default.UnicodeSpeech += onSpeech;
            #endregion

            Thread EggFinderThread = new Thread(FindEggs);
            EggFinderThread.Start();

            ConsoleMessage("Waiting for connection...");
            while (!Profile.IsConnected) ;
            ConsoleMessage("Connection detected.  Welcome {0}!", Self.Name);

            FindFlutes();
            if (Flutes.Count < 0)
                ErrorExit("Not enough snake charmer flutes.  Bye.");

            ConsoleMessage("Starting egg farm...");

            while (Profile.IsConnected)
            {
                MainRoutine();
            }


        }

        private static void MainRoutine()
        {
            DateTime thisTime = DateTime.Now;
            Stealth.Default.ClearJournal();

            #region Search
        Search:
            FindSnakes();
            ConsoleMessage("Found {0} snakes",
                ConsoleColor.DarkYellow, Snakes.Count);
            if (Snakes.Count == 0)
            {
                Thread.Sleep(5000);
                goto Search;
            }

            FindNests();
            ConsoleMessage("Found {0} nests",
                ConsoleColor.DarkYellow, Nests.Count);
            if (Nests.Count == 0)
            {
                Thread.Sleep(5000);
                goto Search;
            }

            FindFlutes();
            ConsoleMessage("Found {0} flutes",
                ConsoleColor.DarkYellow, Flutes.Count);
            if (Flutes.Count < 1)
                ErrorExit("Ran out of flutes.");
            #endregion

            Item Flute = Flutes[0];

            for (int i = 0; i < Snakes.Count; i++)
            {
                if (i == 3)
                    break;

                ConsoleMessage("Attempting flute process...",
                    ConsoleColor.DarkYellow);
                Stealth.Default.CancelWaitTarget();

                while (true)
                {
                    thisTime = DateTime.Now;
                    Flute.Use();
                    if (!Stealth.Default.WaitJournalLine(thisTime, "You must wait a moment for it to recharge.", 750))
                        break;

                    ConsoleMessage("Flute waiting to recharge.  Trying again in 1.5s.",
                        ConsoleColor.DarkRed);
                    Script.Wait(1500);
                }

                Stealth.Default.WaitTargetObject(Snakes[i].ID);
                Script.Wait(1000);
                Stealth.Default.WaitTargetObject(Nests[0].ID);

                Script.Wait(10000);
            }
        }

        static void FindSnakes()
        {
            Find.FindDistance = 10;
            Snakes = Find.FindItems(52);
            Snakes.AddRange(Find.FindItems(21));
            Snakes.AddRange(Find.FindItems(93));
            Snakes.OrderBy(x => x.Distance).ToList();
        }

        static void FindFlutes()
        {
            Flutes = Find.FindItems(0x2807, Self.Backpack.ID);
        }

        static void FindNests()
        {
            Find.FindDistance = 10;
            Nests = Find.FindItems(8755);
            Nests.OrderBy(n => n.Distance).ToList();
        }

        static void FindEggs()
        {
            while (true)
            {

                Find.FindDistance = 10;
                List<Item> Eggs = Find.FindItems(16831);
                if (Eggs.Count > 0)
                {
                    for (int i = 0; i < Eggs.Count; i++)
                    {
                        while (Self.X != Eggs[i].X && Self.Y != Eggs[i].Y)
                        {
                            Script.Wait(1000);
                            Stealth.Default.MoveXY((ushort)Eggs[i].X, (ushort)Eggs[0].Y, false, 0, false);
                            if (Self.X != Eggs[i].X && Self.Y != Eggs[i].Y)
                                break;
                        }
                        ConsoleMessage("Trying to take egg...",
                            ConsoleColor.DarkYellow);
                        Stealth.Default.MoveItem(Eggs[i].ID, 1, Self.Backpack.ID, 0, 0, 0);
                    }
                }
                Script.Wait(10000);
            }
        }
    }
}


Offline Ultimafreak77

  • Full Member
  • ***
  • Posts: 105
  • Activity:
    0%
  • Reputation Power: 2
  • Ultimafreak77 has no influence.
  • Gender: Male
  • Respect: +14
  • Referrals: 0
    • View Profile
Re: [V6, C#] oEggs - Orich's Medusa Egg Farmer
« Reply #18 on: May 23, 2015, 05:41:24 PM »
0
I haven't used the stealth client before but this looks like as good a reason as any to learn.
The few. The proud. The AFK.

Offline Oracle

  • Hero Member
  • *
  • Posts: 888
  • Activity:
    0%
  • Reputation Power: 14
  • Oracle barely matters.Oracle barely matters.
  • Gender: Male
  • We always want something that we cannot have...!
  • Respect: +97
  • Referrals: 3
    • View Profile
Re: [V6, C#] oEggs - Orich's Medusa Egg Farmer
« Reply #19 on: June 12, 2017, 11:57:20 PM »
0
Has this Script been updated.  I really would like a Medusa Egg Farmer written for EasyUO.  I know that there is one written for it, as I had it at one day, but my Hard Drive crashed with all of my cool Scripts I collected on it...!


Oracle
ORACLE
Get me a Straw...because I suck...!
PIXEL CRACK -- Love it! Crave it! Want it! Got to have it!

Tags: