public static void QuestTurnIn(ref Npc npc, string questName, int questId, bool ignoreBlacklist = false, bool forceTravel = false) { if (npc.ForceTravel) { forceTravel = true; } Point me = ObjectManager.ObjectManager.Me.Position; WoWUnit mNpc = ObjectManager.ObjectManager.GetNearestWoWUnit(ObjectManager.ObjectManager.GetWoWUnitByEntry(npc.Entry, true), false, ignoreBlacklist, true); if (mNpc.IsValid && mNpc.CanTurnIn) { npc.Position = mNpc.Position; } WoWGameObject mObj = ObjectManager.ObjectManager.GetNearestWoWGameObject(ObjectManager.ObjectManager.GetWoWGameObjectByEntry(npc.Entry), ignoreBlacklist); if (mObj.IsValid && mObj.CanTurnIn) { npc.Position = mObj.Position; } bool bypassTravel = false; if (me.DistanceTo(npc.Position) <= 800f) { PathFinder.FindPath(npc.Position, out bypassTravel); } if (Usefuls.IsFlying && npc.ContinentIdInt == Usefuls.ContinentId) { bypassTravel = true; } else if (Usefuls.IsFlying) { MountTask.DismountMount(); } if (_travelLocation != null && _travelLocation.DistanceTo(me) > 0.1f) { if (Products.Products.TravelRegenerated && Products.Products.TravelFrom.IsValid) { _travelLocation = Products.Products.TravelFrom; Products.Products.TravelRegenerated = false; } } if (!bypassTravel && (_travelLocation == null || _travelLocation.DistanceTo(me) > 0.1f) && !_travelDisabled) { MovementManager.StopMove(); Logging.Write("Calling travel system for TurnInQuest " + questName + "(" + questId + ") from " + npc.Name + " (" + npc.Entry + ")..."); Products.Products.TravelToContinentId = npc.ContinentIdInt; Products.Products.TravelTo = npc.Position; Products.Products.TravelFromContinentId = Usefuls.ContinentId; Products.Products.TravelFrom = me; Products.Products.ForceTravel = forceTravel; // Pass the check for valid destination as a lambda Products.Products.TargetValidationFct = IsNearQuestGiver; _travelLocation = Products.Products.TravelFrom; return; } if (_travelLocation != null && _travelLocation.DistanceTo(me) <= 0.1f) { _travelDisabled = true; } //Start target finding based on QuestGiver. uint baseAddress = MovementManager.FindTarget(ref npc, 4.5f, true, true, 0f, ignoreBlacklist); if (MovementManager.InMovement) { return; } if (baseAddress > 0) { var tmpNpc = ObjectManager.ObjectManager.GetObjectByGuid(npc.Guid); if (tmpNpc is WoWUnit) { var unitTest = tmpNpc as WoWUnit; if (unitTest.IsValid && unitTest.GetDistance < 20f && !unitTest.CanTurnIn) { _travelDisabled = false; // reset travel nManagerSetting.AddBlackList(unitTest.Guid, 30000); Logging.Write("Npc QuestGiver " + unitTest.Name + " (" + unitTest.Entry + ", distance: " + unitTest.GetDistance + ") cannot TurnIn any quest right now. Blacklisting it for 30 seconds."); return; } } } _travelDisabled = false; // reset travel ItemInfo equip = null; //End target finding based on QuestGiver. if (mObj.IsValid && mObj.GetDistance <= 4.5f || npc.Position.DistanceTo2D(ObjectManager.ObjectManager.Me.Position) < 4.5f && npc.Position.DistanceZ(ObjectManager.ObjectManager.Me.Position) < 6f || npc.Position.DistanceTo(ObjectManager.ObjectManager.Me.Position) < 4.5f) { if (baseAddress <= 0) { npc.Ignore(120000); return; } if (Usefuls.IsFlying) { MountTask.Land(); } InteractTarget(ref npc, baseAddress); Logging.Write("QuestTurnIn " + questName + " (" + questId + ") to " + npc.Name + " (" + npc.Entry + ")"); int id = GetQuestID(); if (GetNumGossipActiveQuests() == 0 && id == questId) { if (Others.IsFrameVisible("QuestFrameCompleteButton") && !Others.IsFrameVisible("QuestFrameCompleteQuestButton")) { Lua.RunMacroText("/click QuestFrameCompleteButton"); Thread.Sleep(300); } equip = CompleteQuest(); Thread.Sleep(Usefuls.Latency + 500); } if (!GetLogQuestId().Contains(questId)) // It's no more in the quest log, then we did turn in it sucessfuly { id = GetQuestID(); FinishedQuestSet.Add(questId); CloseWindow(); AbandonnedId = id; } else { bool systemWorks = GetGossipActiveQuestsWorks(); if (systemWorks) // 2 quest gossip systems = 2 different codes :( { for (int i = 1; i <= GetNumGossipActiveQuests(); i++) { SelectGossipActiveQuest(i); Thread.Sleep(Usefuls.Latency + 500); id = GetQuestID(); if (id == 0) { systemWorks = false; break; } if (id == questId) { if (Others.IsFrameVisible("QuestFrameCompleteButton") && !Others.IsFrameVisible("QuestFrameCompleteQuestButton")) { Lua.RunMacroText("/click QuestFrameCompleteButton"); Thread.Sleep(300); } equip = CompleteQuest(); Thread.Sleep(Usefuls.Latency + 500); // here it can be the next quest id presented automatically when the current one is turned in id = GetQuestID(); CloseWindow(); if (GetLogQuestId().Contains(questId)) { equip = null; Logging.WriteError("Could not turn-in quest " + questId + ": \"" + questName + "\""); break; } FinishedQuestSet.Add(questId); AbandonnedId = id; break; } CloseWindow(); Thread.Sleep(Usefuls.Latency + 500); Interact.InteractWith(baseAddress); Thread.Sleep(Usefuls.Latency + 500); } } if (!systemWorks) { int gossipid = 1; while (GetActiveTitle(gossipid) != "") { SelectActiveQuest(gossipid); Thread.Sleep(Usefuls.Latency + 500); id = GetQuestID(); if (id == questId) { if (Others.IsFrameVisible("QuestFrameCompleteButton") && !Others.IsFrameVisible("QuestFrameCompleteQuestButton")) { Lua.RunMacroText("/click QuestFrameCompleteButton"); Thread.Sleep(300); } equip = CompleteQuest(); Thread.Sleep(Usefuls.Latency + 500); CloseWindow(); if (GetLogQuestId().Contains(questId)) { equip = null; Logging.WriteError("Could not turn-in quest " + questId + ": \"" + questName + "\""); break; } FinishedQuestSet.Add(questId); break; } CloseWindow(); Thread.Sleep(Usefuls.Latency + 500); Interact.InteractWith(baseAddress); Thread.Sleep(Usefuls.Latency + 500); gossipid++; } } } } Thread.Sleep(Usefuls.Latency); if (equip != null) { ItemSelection.EquipItem(equip); Thread.Sleep(Usefuls.Latency + 500); } CloseWindow(); if (!GetLogQuestId().Contains(questId)) { FinishedQuestSet.Add(questId); } }
public static ItemInfo CompleteQuest() { Lua.LuaDoString("CompleteQuest()"); Thread.Sleep(300); string randomString = Others.GetRandomString(Others.Random(4, 10)); Lua.LuaDoString(randomString + " = GetNumQuestChoices()"); int numRewards = Others.ToInt32(Lua.GetLocalizedText(randomString)); Logging.WriteDebug("There is " + numRewards + " rewards"); ItemInfo itemToEquip = null, tempItem; uint valuePriceChoice = 1; uint highestPriceValue = 0; uint valueEquipementChoice = 0; #pragma warning disable 219 uint highestEquipementValue = 0; // if 2 items are usefull, then we need to select one, but how? #pragma warning restore 219 for (uint i = 1; i <= numRewards; i++) { string sLink = Others.GetRandomString(Others.Random(4, 10)); string command = sLink + " = GetQuestItemLink(\"choice\", " + i + "); "; Lua.LuaDoString(command); string link = Lua.GetLocalizedText(sLink); int value = ItemSelection.EvaluateItemStatsVsEquiped(link, out tempItem); if (value > 0) { if (highestPriceValue < value) { highestPriceValue = (uint)value; valuePriceChoice = i; } } else { valueEquipementChoice = i; itemToEquip = tempItem; break; // Let's stop at the first found for now, later we will give them a weight a select the best upgrade } } if (itemToEquip == null) // We have nothing to equip from rewards choice, let's take a look at reward with no choice { randomString = Others.GetRandomString(Others.Random(4, 10)); Lua.LuaDoString(randomString + " = GetNumQuestRewards()"); numRewards = Others.ToInt32(Lua.GetLocalizedText(randomString)); for (uint i = 1; i <= numRewards; i++) { string sLink = Others.GetRandomString(Others.Random(4, 10)); string command = sLink + " = GetQuestItemLink(\"reward\", " + i + "); "; Lua.LuaDoString(command); string link = Lua.GetLocalizedText(sLink); if (ItemSelection.EvaluateItemStatsVsEquiped(link, out tempItem) <= 0) { itemToEquip = tempItem; } } } if (valueEquipementChoice > 0) { Logging.WriteDebug("Going to select reward " + valueEquipementChoice + " for item stats"); Lua.LuaDoString("GetQuestReward(" + valueEquipementChoice + ")"); } else { Logging.WriteDebug("Going to select reward " + valuePriceChoice + " for its money value"); Lua.LuaDoString("GetQuestReward(" + valuePriceChoice + ")"); } Thread.Sleep(500); return(itemToEquip); }