What's new
  • Visit Rebornbuddy
  • Visit Panda Profiles
  • Visit LLamamMagic
  • Visit Resources
  • Visit Downloads
  • Visit Portal

Auctionhouse plugin.

Added Bag handle , items itemcount and stack creating

Code:
namespace Styx.Bot.CustomClasses
{
    using Logic.Inventory.Frames.MailBox;
    using Logic;
    using System;
    using Helpers;
    using Logic.Pathing;
    using System.Threading;
    using System.Diagnostics;
    using Logic.Common.Combat;
    using Object_Dumping_Enumeration;
    using CustomCombat.CombatInterface;
    using Memory_Read_Write_Inject.Lua;
    using Object_Dumping_Enumeration.WoWObjects;
    using System.Collections.Generic;
    using System.IO;
    using System.Runtime.InteropServices;
    using System.Xml.Linq;
    using System.Linq;
    using System.Net;
    using Styx.Plugins.PluginClass;
    using Styx;

    public class AH : HBPlugin
    {
        public Status currentAction = Status.MoveToAuctionner;

        string Totauctions = "";

        //private WoWUnit AHnpc;
        //private WoWGameObject mailbox;
        
        public enum Status
        {
            Idle             = 0,
            MoveToAuctionner = 1,
            MoveToMail       = 2,
            SellingStuff     = 3,
            BuyStuff         = 4,
            Disenchanting    = 5,
            SearchingAH      = 6,
            BottomScan       = 7,
            Waiting          = 8
        }

        private static Stopwatch avoidCrashTimer = new Stopwatch();

        private static Stopwatch waitTimer = new Stopwatch();

        public override void Pulse()
        {
            if (!avoidCrashTimer.IsRunning)
            {
                avoidCrashTimer.Start();

            }
            if (avoidCrashTimer.Elapsed.Seconds < 1)
            {
                return;
            }
            avoidCrashTimer.Reset();

           
            
            switch (currentAction)
            { // temporary statemachine , need better when finishing tests.

                case Status.MoveToAuctionner: //TO_AUCTIONEER                    
                    MoveToAuctioneer();
                    scanAhWithAuctioneerAddon();
                   
                    break;

                case Status.MoveToMail://move to mail and fetch.
                    MoveToMail();
                    break;

                case Status.SellingStuff:
                    //sell stuff here
                    break;

                case Status.BuyStuff:
                    //buying stuff here.
                    break;
                case Status.SearchingAH:
                    //should wait until completion
                    //todo: add completion checks
                    
                    break;
                case Status.Waiting:
                    if (waitTimer.Elapsed.Minutes > 2)
                        currentAction = Status.Idle;
                    break;
                case Status.Idle:
                    // do something
                    //shouldnt really just move to auctionner, but make maintenance checks
                    if (CheckMail() /*todo: and bags are not full*/)
                    {
                        currentAction = Status.MoveToMail;
                        return;
                    }
                    currentAction = Status.MoveToAuctionner;
                    break;

                default:
                    Thread.Sleep(1000);
                    break;
            }
        }
        //
        //
        //
        //
        public bool TargetUnit(uint Nom)
        {
            ObjectManager.Update();
            Thread.Sleep(1000);

            foreach (WoWUnit wu in ObjectManager.GetObjectsOfType<WoWUnit>())
            {
                if (wu.Entry == Nom)
                {
                    Logging.Write(wu.Name + " is now my target!");
                    wu.Target();
                }
            }

            Thread.Sleep(1000);
            if (ObjectManager.Me.CurrentTarget.Entry == Nom)
            {

                return true;
            }
            return false;
        }
        //
        //
        //
        //
        public bool TargetObj(uint Nom)
        {
            ObjectManager.Update();
            Thread.Sleep(1000);

            foreach (WoWGameObject wa in ObjectManager.GetObjectsOfType<WoWGameObject>())
            {
                if (wa.Entry == Nom)
                {
                    wa.Interact();
                }
            }
            Thread.Sleep(1000);
            if (ObjectManager.Me.CurrentTarget.Entry == Nom)
            {
                return true;
            }
            return false;
        }

        public bool MoveToAuctioneer()
        {
            WoWUnit ahnpc = findNearestAH();
            //this need better loggic.maybe using Frames
            var wp = ahnpc.Location;

            if (wp.Distance(ObjectManager.Me.Location) > 5)
            {
                Navigator.GeneratePathFromMe(wp);
                Logging.Write("Moving to Auctioneer");

                while (wp.Distance(ObjectManager.Me.Location) > 5)
                {
                    Navigator.MoveTo(wp);
                    Navigator.Pulse();
                }
                Thread.Sleep(1000);
                //findNearestAH());
                //TargetUnit(findNearestAH().Guid);
                findNearestAH().Target();
                Thread.Sleep(1000);
                ObjectManager.Me.CurrentTarget.Interact();
                Thread.Sleep(2000);
                Lua.DoString("QueryAuctionItems(\"Eternal Fire\",\"\",\"\",nil,nil,nil,nil,nil,nil)");// Eternal fire hardcoded. Styx has some AH stuff inside already.
                Thread.Sleep(1000);
                Logging.Write("Displayed Auction lines:  " + TotalAuctionLines());
            }
            return true;
        }
       
        public bool MoveToMail()
        {
            WoWGameObject mail = findNearestMailbox();

            var wp = mail.Location;
            var ml = new MailFrame();
            Navigator.GeneratePathFromMe(mail.Location);
            Logging.Write("Moving to Mail");
            while (wp.Distance(ObjectManager.Me.Location) > 5)
            {
                Navigator.MoveTo(mail.Location);
                Navigator.Pulse();
            }
            if (wp.Distance(ObjectManager.Me.Location) < 5)
            {
                //TargetObj(173221);
                mail.Interact();
                Thread.Sleep(3000);
                while (Convert.ToInt32(ml.MailCount.ToString()) > 0)
                {
                    Logging.Write("Standing at Mailbox for collecting mails: " + ml.MailCount.ToString());
                    Thread.Sleep(1000);
                    ml.GetMailAttachments(1);
                }
                currentAction = Status.MoveToAuctionner;
            }
            currentAction = Status.MoveToAuctionner;

            //found greens?
            GetGreens();
            return true;

        }
        public string TotalAuctionLines()
        {
            Lua.DoString("Totauctions = GetNumAuctionItems(\"list\")");
            Totauctions = Lua.GetLocalizedText("Totauctions");

            return Totauctions;
        }

        public bool CheckMail()
        {
            int IHave = 0;
            Lua.DoString("IHave = HasNewMail()");
            IHave = Convert.ToInt32(Lua.GetLocalizedText("IHave"));
            Logging.Write("Gonna check for new mail");// Debug spam.
            if (IHave > 0)
            {
                currentAction = Status.MoveToMail;

                return true;
            }
            return false;
        }

        public WoWGameObject findNearestMailbox()
        {
            ObjectManager.Update();
            Thread.Sleep(1000);
            foreach (WoWGameObject wu in ObjectManager.GetObjectsOfType<WoWGameObject>())
            {
                if (wu.Name == "Mailbox")
                {
                    Logging.Write("Found " + wu.Name + " at: [" + wu.Location.X + "," + wu.Location.Y + "," + wu.Location.Z+"]");
                    return wu;
                }
            }
            return null;
        }
        public WoWUnit findNearestAH()
        {
            ObjectManager.Update();
            Thread.Sleep(1000);
            foreach (WoWUnit wu in ObjectManager.GetObjectsOfType<WoWUnit>())
            {
                if (wu.IsAuctioneer) //&& Navigator.CurrentMesh.IsPointPathingAvailable(wu.Location))
                {
                    Logging.Write("Found " + wu.Name + " at: [" + wu.Location.X + "," + wu.Location.Y + "," + wu.Location.Z+"]");
                    return wu;
                }
            }
            return null;
        }





        public void scanAhWithAuctioneerAddon()
        {
            Logging.Write("Searching AH");
            Lua.DoString("if (AucAdvScanButton:IsVisible()) then AucAdvScanButton:Click() end");
            currentAction = Status.SearchingAH;
            waitTimer.Reset();
            waitTimer.Start();
            
        }





        public void PickupNumberOfItems(string itemName, int numberToPickup)
        {
            MakeStacks(itemName);
            Thread.Sleep(1000);
            Lua.DoString(
                "for bag=0,4 do " + //foreach bag
                    "for slot=1,GetContainerNumSlots(bag) do " + //foreach item in bag"
                        "local item = GetContainerItemLink(bag,slot) " +
                        "if item and item:find(\"" + itemName + "\") then " +
                            "local _,itemCount = GetContainerItemInfo(bag,slot) " +
                            "if itemCount>" + (numberToPickup - 1) + " then " +
                                "local a=0 local b=0 " +
                                "for x=0,4 do " +
                                    "for y=1,GetContainerNumSlots(x) do " +
                                        "if not GetContainerItemLink(x,y) then " +
                                            "a=x b=y " +
                                        "end " +
                                    "end " +
                                "end " +
                              "if b > 0 then " +
                            "ClearCursor() " +
                          "repeat " +
                        "local_,_,locked1 = GetContainerItemInfo(bag,slot) " +
                    "local_,_,locked2 = GetContainerItemInfo(a,b) " +
                "until not locked1 and not locked2 " +
                                    "SplitContainerItem(bag,slot," + numberToPickup + ") " +
                                    "PickupContainerItem(a,b) " +
                                    "bag=1000 slot=1000 " +
                                "end " +
                            "end " +
                        "end " +
                    "end " +
                "end");
            Thread.Sleep(1000);
            Lua.DoString(
                "for bag=0,4 do " + //foreach bag
                    "for slot=1,GetContainerNumSlots(bag) do " + //foreach item in bag"
                        "local item = GetContainerItemLink(bag,slot) " +
                        "if item and item:find(\"" + itemName + "\") then " +
                            "local _,itemCount = GetContainerItemInfo(bag,slot) " +
                            "if itemCount==" + numberToPickup + " then " +
                                "PickupContainerItem(bag,slot) " +
                                "bag=1000 slot=1000 " +
                            "end " +
                        "end " +
                    "end " +
                "end");
        }





        private void MakeStacks(string itemName)
        {
            Lua.DoString(
                "for bag=0,4 do " + //foreach bag
                    "for slot=1,GetContainerNumSlots(bag) do " + //foreach item in bag"
                        "local item = GetContainerItemLink(bag,slot) " +
                        "if item and item:find(\"" + itemName + "\") then " +
                            "PickupContainerItem(bag,slot) " +
                            "local t,x,c=GetCursorInfo()if t==\"item\"then for i=0,4 do for j=1,28 do _,c,t=GetContainerItemInfo(i,j)if c and c>0 and c<select(8,GetItemInfo(x))and not t and strmatch(GetContainerItemLink(i,j)or\"\",\"m:\"..x)then PickupContainerItem(i,j)end end end end " +
                        "end " +
                    "end " +
                "end");
        }
        //
        //
        //
        //
        #region Disenchanting
        //todo: add more
        private void GetGreens()
        {
            var items = ObjectManager.GetObjectsOfType<WoWItem>(false);
            var notSoulbound = items.Where(obj => !obj.IsSoulbound &&
                obj.Quality == WoWItemQuality.Uncommon).ToList();

            foreach (WoWItem item in notSoulbound)
            {
                Logging.Write("{0} is not soulbound", item.Name);
            }
        }
        #endregion


        public override string Name { get { return "Auctioneer Fixed"; } }

        public override string Author { get { return "Morgalis and MrBig"; } }

        public override Version Version { get { return new Version(1, 2); } }

        public override bool WantButton { get { return false; } }
    }
}
 
Will this be able to grab a set number of stacks out of a bank/guild bank?
 
As you can see
GetContainerNumSlots

means bags. But i am sure that same code should work on bank when using bank functions.
 
Hey, i am on vacation, in Spain, but the weather is bad right now, will probably have to cancel :/

Never the less, if you dont hear from me for some days you know why xD
 
Last edited:
I've been trying to improve this code to fit my needs but I failed at two things.

First I just can?t access information on what items are stored in guild bank - ObjectManager.GetObjectsOfType<WoWItem> only returns items in bags and bank not guild bank.
I looked through all Blizzard API functions and found just one texture, count, locked = GetGuildBankItemInfo(tab, slot)
But it doesn't seem to return needed information and I wouldn?t know how to use it anyway (any functions that retrieve values from LUA scripts ?).

Second I don?t know how to ?push? Refresh button with alt on Auctioneer Appraiser tab and Batch post + Alt +Ctr + Shift. What code/script could do that?

If you guys can help me with any of the above I?d be grateful.
 
We are debugging erenion's. I hope to release in an hour or so.
 
OMG this will be so freaking good, i can't even belive it!!
 
How to run.

Erenion did a very good job at keeping it dependancy free, no need for other addons :)
Hi, mate

I've been wondering, what program u use to run the code.
Personally last day i began to think: "How to make a AH Bot using G15 Keyboard"
And i probably got the answer, just need to be tested ill do in a few days....
Ill gladly post if i got it run in the later days, just want u to answer my question.

Ps.
U guys are AWESOME
 
Back
Top