Jump to content
  • [Suggestion] allow custom scripts into reward item


    TheSmokie
    • Version: All Product: Quester Type: Suggestion Status: Added

    Hello @Droidz,

    my team and i are trying to writing a custom script to over ride Quest item choose rewards, and would love if you could add a option a option to use custom script on the quest reward frame.

    The only way I could find to take over the item selection would be to write a full override of the turn-in on every single quest, which would be alot of work. It would be ideal if the reward item field could take lua that can run when the gossip menu is open and the custom lua simply returns the reward item number. this will allow code that can determine the item based on stats, then return the preferred reward item number. After that let the rest of wrobots turn-in code do its thing

     

    This is a big feature and would make quester product even better. and more afkable.



    User Feedback

    Recommended Comments

    Hello, wait next update, I added even:

    wManager.Events.OthersEvents.OnSelectQuestRewardItem += delegate(CancelEventArgs cancelable)
    {
    
    };

    if you cancel event WRobot will not select reward item.

    Link to comment
    Share on other sites

    This is great. Now I don't have to use a Lua hook anymore. 

    Otherwise you can use a Lua hook to create a race condition between your selection code and ANY code turning in the quest:
     

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Linq;
    using System.Reflection;
    using System.Security.Cryptography;
    using System.Text.RegularExpressions;
    using System.Threading;
    using System.Threading.Tasks;
    using DatabaseManager.Enums;
    using robotManager.Events;
    using robotManager.FiniteStateMachine;
    using robotManager.Helpful;
    using robotManager.Products;
    using wManager;
    using wManager.Wow.Bot.Tasks;
    using wManager.Wow.Class;
    using wManager.Wow.Enums;
    using wManager.Wow.Helpers;
    using wManager.Wow.ObjectManager;
    
    public class QuestRewardSelector
    {
        public static string TooltipName = "QuestItemCompareTooltip";
        
        public static void Start()
        {
            TooltipName = LuaVariableSettings.CurrentSetting.QuestToolTipName;
            RegisterHook();
            CreateTooltip();
            EventsLua.AttachEventLua((LuaEventsId) Enum.Parse(typeof(LuaEventsId), "QUEST_COMPLETE"), QuestCompleteHandler);
        }
    
        public static void Stop()
        {
            
        }
    
        public static void CreateTooltip()
        {
            Lua.LuaDoString([email protected]"
            if not {TooltipName} then
                {TooltipName} = CreateFrame('GameTooltip', '{TooltipName}', nil, 'GameTooltipTemplate'); 
                {TooltipName}:SetOwner(UIParent, 'ANCHOR_NONE');
            end
            ");
        }
    
        public static void RegisterHook()
        {
            Lua.LuaDoString([email protected]"
                if (not {LuaVariableSettings.CurrentSetting.QuestHookName}) then
                    _OriginalQuestCompleteOnClick = QuestFrameCompleteQuestButton:GetScript(""OnClick"");
                    function hook_QuestComplete(self, button, arg2, arg3)
                        self = this;
                        if (button == ""FORCE"") then
                            --DEFAULT_CHAT_FRAME:AddMessage('Forcing quest acceptance!');
                            _OriginalQuestCompleteOnClick(self, button);
                        else       
                            C_Timer.After(2500, function()
                                --DEFAULT_CHAT_FRAME:AddMessage('Delay quest turn in by 2500ms');
                                _OriginalQuestCompleteOnClick(self, button);
                            end);    
                        end
                    end
                    QuestFrameCompleteQuestButton:SetScript(""OnClick"", hook_QuestComplete);
    
                    _GetQuestReward = GetQuestReward;
                    function GetQuestReward(index, force)
                        if(force) then
                            return _GetQuestReward(index);
                        else
                            C_Timer.After(2500, function()
                                --DEFAULT_CHAT_FRAME:AddMessage('Delay quest turn in by 2500ms');
                                return _GetQuestReward(index);
                            end);
                        end
                    end
    
                    --DEFAULT_CHAT_FRAME:AddMessage('Quest hook initiated');
                    {LuaVariableSettings.CurrentSetting.QuestHookName} = true;
                end
            ");
        }
    
        private static void QuestCompleteHandler(object context)
        {
            Lua.LuaDoString("QuestFrameCompleteQuestButton:Disable();");
            PluginLog.Log("About to complete quest - INTERCEPT!");
            SelectQuestItem();
            Lua.LuaDoString("QuestFrameCompleteQuestButton:Enable();");
            //fallback
            Lua.LuaDoString($"_GetQuestReward(1);");
        }
    
        private static void SelectQuestItem()
        {
            try
            {
                int questRewards = Lua.LuaDoString<int>("return GetNumQuestChoices()");
                if (questRewards == 0)
                {
                    return;
                }
    
                Dictionary<ParsedItem, int> itemRewards = new Dictionary<ParsedItem, int>();
                for (int i = 1; i <= questRewards; i++)
                {
                    Lua.LuaDoString([email protected]"
                            {TooltipName}:Hide();
                            {TooltipName}:SetOwner(UIParent, 'ANCHOR_NONE');
                            {TooltipName}:ClearLines();
                            {TooltipName}:SetQuestItem(""choice"", {i});
                     ");
    
                    ParsedItem item = ItemParser.ParseCurrentTooltip(TooltipName, true);
                    if (item.isUsable)
                    {
                        itemRewards.Add(item, i);
                    }
                }
    
                ItemComparator comparator = new ItemComparator(StatWeights.ForClass(ObjectManager.Me.WowClass));
                ParsedItem bestItem = comparator.FindBestItem(itemRewards.Keys.ToList());
    
                int index = itemRewards[bestItem];
                PluginLog.Log("Found best item " + bestItem.name + " as reward number: " + index);
                Lua.LuaDoString([email protected]"
                    --QuestFrameCompleteQuestButton:Enable();
                    _GetQuestReward({index});
                ");
                Thread.Sleep(1000);
            }
            catch (Exception e)
            {
                Logging.WriteError("" + e);
            }
        }
    
        private static async void SelectQuestItemAsync()
        {
            await Task.Run(() =>
            {
                SelectQuestItem();
            });
        }
    }

     

    Link to comment
    Share on other sites


    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Add a comment...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...