Jump to content

[Free] Basic Plugin for handing in Damaged Necklaces for Jewelcrafter tokens (WOTLK) [Source Included]


MrCeeJ

Recommended Posts

So after grinding for a while in northrend you will probably have hundreds of these, if you actually want to turn them in yourself it can take a long time, so I wrote a little plugin to do it for you. You need the Damaged Necklaces and Gems in your inventory, and need to be near the Grand Master trainer in Dalaran in order to spam turn them in. To use the plugin just save it in your plugins folder, turn on WRotation and hit go. Some plugins can interfere with it (when they pause the bot) but it should be ok, you can always turn them off while running it.
 

Finally here is the source code, feel free to give me suggestions to make it better, I just hacked away using the API until it worked, so I am sure there are better ways of doing things, so happy to take suggestions and improve it (which is really why I'm posting it here).

 

The source is also attached for easy downloading.

 

Have fun 🙂

 

using System;
using robotManager.Helpful;
using wManager.Wow.Helpers;

using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;

using robotManager.FiniteStateMachine;
using robotManager.Products;
using Timer = robotManager.Helpful.Timer;
using wManager.Plugin;
using wManager.Wow.Bot.States;
using wManager.Wow.Enums;
using wManager.Wow.ObjectManager;
using wManager.Wow.Class;

public class Main : wManager.Plugin.IPlugin
{
    public void Initialize()
    {
        Logging.Write("JCTokenTurnIn: Started.");       
        MakeAllTokens();        
    }

    private void MakeAllTokens(){
        bool crafting = true;    
        int count = 0;
        while(crafting) {
            if (HaveRepairedItem()) {
                TurnIn();
                count++;
            } else if (HaveQuest()){
                RepairItem();
            } else if (HaveItems()) {
                AcceptQuest();
            } else {
                crafting = false;
            }
        }
        Logging.Write("JCTokenTurnIn: Finished, tokens made: "+count);
    }

    private bool HaveRepairedItem() {
        return HaveItemId(43298);
    }

    private void TurnIn() {
        wManager.Wow.Bot.Tasks.GoToTask.ToPositionAndIntecractWithNpc(wManager.Wow.ObjectManager.ObjectManager.Me.Position, 28701);                
        System.Threading.Thread.Sleep(128);
        Quest.SelectGossipActiveQuest(1);
        System.Threading.Thread.Sleep(128);
        Quest.CompleteQuest();
        System.Threading.Thread.Sleep(256);       
    }

    private bool HaveQuest() {
        return HaveItemId(43299);
    }

    private void RepairItem() {
       foreach (WoWItem item in Bag.GetBagItem())
        {
            ItemInfo info = item.GetItemInfo;
            int ItemId = getId(info.ItemLink);
            if (ItemId == 43299) {
               List<int> bagAndSlot = Bag.GetItemContainerBagIdAndSlot(info.ItemName);
               Lua.LuaDoString("UseContainerItem(" + bagAndSlot[0] + "," + bagAndSlot[1] + ")");
               System.Threading.Thread.Sleep(12500);
               return;
            }                
        }       
    }

    private bool HaveItems() {
        return HaveItemId(43297) && HaveItemId(36923);
    }

    private void AcceptQuest() {
        foreach (WoWItem item in Bag.GetBagItem())
        {
            ItemInfo info = item.GetItemInfo;
            int ItemId = getId(info.ItemLink);
            if (ItemId == 43297) {
               List<int> bagAndSlot = Bag.GetItemContainerBagIdAndSlot(info.ItemName);
                Lua.LuaDoString("UseContainerItem(" + bagAndSlot[0] + "," + bagAndSlot[1] + ")");
                Lua.LuaDoString("AcceptQuest()");
            }                
        }
        
    }

    private bool HaveItemId(int Id) {
        foreach (WoWItem item in Bag.GetBagItem())
        {
            ItemInfo info = item.GetItemInfo;
            int ItemId = getId(info.ItemLink);
            if (ItemId == Id) {
                return true;
            }                
        }
        return false;
    }

    private int getId(String itemLink){
        String pattern = "Hitem:";    
        int index = itemLink.IndexOf(pattern);
        return Int32.Parse(itemLink.Substring(index+6).Split(':')[0]);
    }

    public void Settings()
    {}

    public void Dispose()
    {
        Logging.Write("JCTokenTurnIn: Stopped.");
    }

}

 

JCTokenTurnIn.cs

Edited by MrCeeJ
Added flair to title
Link to comment
Share on other sites

  • MrCeeJ changed the title to [Free] Basic Plugin for handing in Damaged Necklaces for Jewelcrafter tokens (WOTLK) [Source Included]

I have refactored it a little, to suit my preferred 'functional' style. Not sure if it is everyone's cup of tea so I'll leave the original, but I do enjoy being able to chain functions with simple boolean return values, and it makes it very easy to compose and modify things like dps rotations that can form very complex decision trees.

I am curious what other devs think, it is full of side-effects and empty statements, which are normally considered smells as they can make the code hard to understand and work with, but since the purpose of the refactoring is to make it easier to understand and work with I don't think they are necessarily valid objections here.

Finally, I am sorry the capitalisation is all over the place, coming from a Java / Python / Prolog background the .net capitalisation always confuses me..

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;

using robotManager.Helpful;
using robotManager.FiniteStateMachine;
using robotManager.Products;

using wManager.Plugin;
using wManager.Wow.Helpers;
using wManager.Wow.Bot.States;
using wManager.Wow.Enums;
using wManager.Wow.ObjectManager;
using wManager.Wow.Class;

public class Main : wManager.Plugin.IPlugin
{
    public void Initialize()
    {
        Logging.Write("JCToken: Started.");
        int count = 0;
        while (TurnIn() || Repair() || GetQuest()){}
        Logging.Write("JCToken: Finished");
    }

    private bool TurnIn()
    {
        return HaveRepairedItem() && CompleteQuest();
    }

    private bool Repair()
    {
        return HaveQuest() && RepairItem();
    }

    private bool GetQuest()
    {
        return HaveItems() && AcceptQuest();
    }

    private bool HaveRepairedItem()
    {
        return HaveItemId(43298);
    }

    private void CompleteQuest()
    {
        wManager.Wow.Bot.Tasks.GoToTask.ToPositionAndIntecractWithNpc(ObjectManager.Me.Position, 28701);
        System.Threading.Thread.Sleep(128);
        Quest.SelectGossipActiveQuest(1);
        System.Threading.Thread.Sleep(128);
        Quest.CompleteQuest();
        System.Threading.Thread.Sleep(256);
        return true;
    }

    private bool HaveQuest()
    {
        return HaveItemId(43299);
    }

    private bool RepairItem()
    {
        foreach (WoWItem item in Bag.GetBagItem())
        {
            ItemInfo info = item.GetItemInfo;
            int itemId = GetId(info.ItemLink);
            if (itemId == 43299)
            {
                List<int> bagAndSlot = Bag.GetItemContainerBagIdAndSlot(info.ItemName);
                Lua.LuaDoString("UseContainerItem(" + bagAndSlot[0] + "," + bagAndSlot[1] + ")");
                System.Threading.Thread.Sleep(12500);
                return true;
            }
        }
        return false;
    }

    private bool HaveItems()
    {
        return HaveItemId(43297) && HaveItemId(36923);
    }

    private bool AcceptQuest()
    {
        foreach (WoWItem item in Bag.GetBagItem())
        {
            ItemInfo info = item.GetItemInfo;
            int itemId = GetId(info.ItemLink);
            if (itemId == 43297)
            {
                List<int> bagAndSlot = Bag.GetItemContainerBagIdAndSlot(info.ItemName);
                Lua.LuaDoString("UseContainerItem(" + bagAndSlot[0] + "," + bagAndSlot[1] + ")");
                Lua.LuaDoString("AcceptQuest()");
                return true;
            }
        }
        return false;
    }

    private bool HaveItemId(int Id)
    {
        foreach (WoWItem item in Bag.GetBagItem())
        {
            ItemInfo info = item.GetItemInfo;
            int itemId = GetId(info.ItemLink);
            if (itemId == Id)
            {
                return true;
            }
        }
        return false;
    }

    private int GetId(String itemLink)
    {
        String pattern = "Hitem:";
        int index = itemLink.IndexOf(pattern);
        return Int32.Parse(itemLink.Substring(index + 6).Split(':')[0]);
    }

    public void Settings(){}

    public void Dispose()
    {
        Logging.Write("JCToken: Stopped.");
    }

}

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...