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 void LongMoveGo(Point point) { try { //MovementManager.StopMove(); int timer = Others.Times; if (_used) { _used = false; while (_usedLoop) { Thread.Sleep(5); } } _used = true; _usedLoop = true; //MovementManager.StopMove(); MountTask.Mount(false, true); Point pTemps = ObjectManager.ObjectManager.Me.Position; Timer timerSit = new Timer(2500); bool flyingPathFinder = false; while (Products.Products.IsStarted && (ObjectManager.ObjectManager.Me.IsMounted || MountTask.GetMountCapacity() == MountCapacity.Feet) && ObjectManager.ObjectManager.Me.Position.DistanceTo(point) > 3.5f && _used && _usedLoop) { bool forceGround = false; if (Usefuls.IsFlying) { Point pos = ObjectManager.ObjectManager.Me.Position; if (point.DistanceTo2D(pos) <= 60 || flyingPathFinder && point.DistanceTo2D(pos) <= 110) { Point p = new Point(ObjectManager.ObjectManager.Me.Position.LerpByDistance(point, 3f)); bool failed = false; Point targetPoint = new Point(); if (p.IsValid && TraceLine.TraceLineGo(ObjectManager.ObjectManager.Me.Position, p, CGWorldFrameHitFlags.HitTestAllButLiquid)) { if ((point.DistanceTo2D(pos) <= 60 || flyingPathFinder && point.DistanceTo2D(pos) <= 110)) { float degree = 0f; bool doContinue = false; try { LongMoveIsLanding = true; while (degree < 360) { var rnd = new Random(); float radius = rnd.Next(25, 50); float x = (float)(pos.X + radius * System.Math.Cos(Math.DegreeToRadian(degree))); float y = (float)(pos.Y + radius * System.Math.Sin(Math.DegreeToRadian(degree))); Point topPoint = new Point(x, y, pos.Z); Point bottomPoint = new Point(x, y, PathFinder.GetZPosition(x, y)); if (!TraceLine.TraceLineGo(topPoint, new Point(topPoint.LerpByDistance(point, 3f)), CGWorldFrameHitFlags.HitTestAllButLiquid)) { targetPoint = topPoint; MovementManager.MoveTo(targetPoint); Thread.Sleep(2500); flyingPathFinder = true; doContinue = true; break; // we want to go to topPoint and directly go to point. } else if (!TraceLine.TraceLineGo(topPoint, bottomPoint, CGWorldFrameHitFlags.HitTestAllButLiquid)) { bool success; PathFinder.FindPath(bottomPoint, point, Usefuls.ContinentNameMpq, out success); if (success) { targetPoint = topPoint; MovementManager.MoveTo(targetPoint); Thread.Sleep(2500); flyingPathFinder = true; break; // we want to go to topPoint then dismount down to bottomPoint, then findPath to target. } } float randomDegree = rnd.Next(20, 30); degree += randomDegree; if (degree >= 360f) { failed = true; } } } finally { LongMoveIsLanding = false; } if (doContinue) { Thread.Sleep(1000); continue; } } if (!failed) { if (ObjectManager.ObjectManager.Me.Position.DistanceTo(targetPoint) > 5f) { Thread.Sleep(2500); } if (ObjectManager.ObjectManager.Me.Position.DistanceTo(targetPoint) > 5f) { continue; } MountTask.DismountMount(); _used = false; _usedLoop = false; return; } } else { MovementManager.MoveTo(p); flyingPathFinder = false; } } } if (MountTask.GetMountCapacity() <= MountCapacity.Ground || forceGround) { if (RegenPath.IsReady && ObjectManager.ObjectManager.Me.Position.DistanceTo(point) > 3.5f) { RegenPath = new Timer(1000 * 60); List <Point> getFullPath = PathFinder.FindPath(point); MovementManager.Go(getFullPath); RegenPath.Reset(); } else { Thread.Sleep(1000); } } else { if (!MovementManager.IsUnStuck) { if (ObjectManager.ObjectManager.Me.IsDeadMe) { return; } const int checkInFront = 130; // was 100 const int checkCollision = 60; // was 40 if (ObjectManager.ObjectManager.Me.Position.DistanceTo2D(point) > 15) { Point meTemps = ObjectManager.ObjectManager.Me.Position; meTemps.Z = meTemps.Z - 2; Point temps = new Point(point.X, point.Y, ObjectManager.ObjectManager.Me.Position.Z - 2.5f); if (point.DistanceTo(ObjectManager.ObjectManager.Me.Position) > checkInFront) { temps = Math.GetPosition2DOfLineByDistance(ObjectManager.ObjectManager.Me.Position, point, checkInFront); temps.Z = ObjectManager.ObjectManager.Me.Position.Z - 2.5f; } if (TraceLine.TraceLineGo(meTemps, temps) || (ObjectManager.ObjectManager.Me.Position.Z + 10 < point.Z && point.DistanceTo2D(ObjectManager.ObjectManager.Me.Position) < 100)) { MovementsAction.Descend(false); MovementsAction.Ascend(true); timerSit = new Timer(1000); // If distance to colission < checkCollision stop moveto temps = new Point(point.X, point.Y, ObjectManager.ObjectManager.Me.Position.Z - 2.5f); if (point.DistanceTo(ObjectManager.ObjectManager.Me.Position) > checkInFront) { temps = Math.GetPosition2DOfLineByDistance(ObjectManager.ObjectManager.Me.Position, point, checkCollision); temps.Z = ObjectManager.ObjectManager.Me.Position.Z - 2.5f; } if (TraceLine.TraceLineGo(meTemps, temps)) { MovementManager.StopMoveTo(false); } // End Stop move to Thread.Sleep(800); if (pTemps.DistanceTo(ObjectManager.ObjectManager.Me.Position) < 1f) { MovementManager.UnStuckFly(); } else { pTemps = ObjectManager.ObjectManager.Me.Position; } } else { MovementsAction.Ascend(false); if (timerSit.IsReady) { // If distance to ground > 100 temps = new Point(ObjectManager.ObjectManager.Me.Position.X, ObjectManager.ObjectManager.Me.Position.Y, ObjectManager.ObjectManager.Me.Position.Z - altitude); Point tempsMe = new Point(ObjectManager.ObjectManager.Me.Position.X, ObjectManager.ObjectManager.Me.Position.Y, ObjectManager.ObjectManager.Me.Position.Z + 5f); Point temps2 = Math.GetPosition2DOfLineByDistance(tempsMe, point, 80); temps2.Z = ObjectManager.ObjectManager.Me.Position.Z - altitude; if (!TraceLine.TraceLineGo(tempsMe, temps)) { if (!TraceLine.TraceLineGo(tempsMe, temps2)) { MovementsAction.Descend(true); } else { timerSit = new Timer(1000); MovementsAction.Descend(false); } } else { timerSit = new Timer(1000); MovementsAction.Descend(false); } // End Stop move ground } MovementManager.MoveTo(point.X, point.Y, ObjectManager.ObjectManager.Me.Position.Z); if (Others.Times > (timer + 1500)) { MovementManager.MoveTo(point.X, point.Y, ObjectManager.ObjectManager.Me.Position.Z); timer = Others.Times; } } } else { MovementsAction.Descend(false); MovementsAction.Ascend(false); if (ObjectManager.ObjectManager.Me.Position.DistanceTo2D(point) <= 5f && ObjectManager.ObjectManager.Me.Position.DistanceZ(point) > 2f) { MovementsAction.Descend(false); MovementsAction.Ascend(false); MovementManager.StopMove(); MovementManager.StopMove(); MountTask.Land(); } else { MovementManager.MoveTo(point); } } } if (ObjectManager.ObjectManager.Me.IsMounted && !Usefuls.IsFlying) { MovementsAction.Descend(false); MovementsAction.Ascend(false); MountTask.Mount(false, true); MovementsAction.Ascend(true); Thread.Sleep(1300); MovementsAction.Ascend(false); } } Thread.Sleep(150); //50 } MovementsAction.Descend(false); MovementsAction.Ascend(false); _used = false; _usedLoop = false; RegenPath.ForceReady(); } catch (Exception exception) { MovementsAction.Descend(false); MovementsAction.Ascend(false); Logging.WriteError("LongMove > LongMoveGo(Point point): " + exception); _used = false; _usedLoop = false; RegenPath.ForceReady(); } }
public static void QuestPickUp(ref Npc npc, string questName, int questId, out bool cancelPickUp, bool ignoreBlacklist = false, bool forceTravel = false) { if (npc.ForceTravel) { forceTravel = true; } cancelPickUp = false; if (AbandonnedId == questId) // should happen only when we do a different quest requirement for optimization { AbandonnedId = 0; return; } if (AbandonnedId != 0) { AbandonQuest(AbandonnedId); } AbandonnedId = 0; Point me = ObjectManager.ObjectManager.Me.Position; WoWUnit mNpc = ObjectManager.ObjectManager.GetNearestWoWUnit(ObjectManager.ObjectManager.GetWoWUnitByEntry(npc.Entry, true), false, ignoreBlacklist, true); // We have the NPC in memory and he is closer than the QuesterDB entry. (some Npc moves) if (mNpc.IsValid && mNpc.HasQuests) { npc.Position = mNpc.Position; } WoWGameObject mObj = ObjectManager.ObjectManager.GetNearestWoWGameObject(ObjectManager.ObjectManager.GetWoWGameObjectByEntry(npc.Entry), ignoreBlacklist); if (mObj.IsValid && mObj.HasQuests) { 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 PickUpQuest " + 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); // can pick up quest on dead NPC. if (MovementManager.InMovement) { return; } _travelDisabled = false; // reset travel 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.HasQuests) { _travelDisabled = false; // reset travel nManagerSetting.AddBlackList(unitTest.Guid, 30000); Logging.Write("Npc QuestGiver " + unitTest.Name + " (" + unitTest.Entry + ", distance: " + unitTest.GetDistance + ") does not have any available quest for the moment. Blacklisting it for 30 seconds."); cancelPickUp = true; return; } } } //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) { cancelPickUp = true; // We are there but no NPC waiting for us. // This code is there for Mimesis and I'm not currently working on Quester, so I'm not going to "return;" there as quester will be even more lost. npc.Ignore(120000); return; } if (Usefuls.IsFlying) { MountTask.Land(); } InteractTarget(ref npc, baseAddress); Logging.Write("PickUpQuest " + questName + " (" + questId + ") from " + npc.Name + " (" + npc.Entry + ")"); int id = GetQuestID(); if (GetNumGossipAvailableQuests() == 0 && id == questId) { AcceptQuest(); Thread.Sleep(Usefuls.Latency + 500); } if (GetLogQuestId().Contains(questId)) { CloseWindow(); } else { bool systemWorks = GetGossipAvailableQuestsWorks(); if (systemWorks) // 2 quest gossip systems = 2 different codes :( { for (int i = 1; i <= GetNumGossipAvailableQuests(); i++) { SelectGossipAvailableQuest(i); Thread.Sleep(Usefuls.Latency + 500); id = GetQuestID(); if (id == 0) { systemWorks = false; break; } if (id == questId) { AcceptQuest(); Thread.Sleep(Usefuls.Latency + 500); id = GetQuestID(); CloseWindow(); if (id != questId) { AbandonQuest(id); } break; } CloseWindow(); Thread.Sleep(Usefuls.Latency + 500); AbandonQuest(id); Interact.InteractWith(baseAddress); Thread.Sleep(Usefuls.Latency + 500); } } if (!systemWorks) { int gossipid = 1; while (GetAvailableTitle(gossipid) != "") { SelectAvailableQuest(gossipid); Thread.Sleep(Usefuls.Latency + 500); id = GetQuestID(); if (id == questId) { AcceptQuest(); Thread.Sleep(Usefuls.Latency + 500); id = GetQuestID(); CloseWindow(); if (id != questId) { AbandonQuest(id); } break; } CloseWindow(); Thread.Sleep(Usefuls.Latency + 500); AbandonQuest(id); Interact.InteractWith(baseAddress); Thread.Sleep(Usefuls.Latency + 500); gossipid++; } } } KilledMobsToCount.Clear(); Thread.Sleep(Usefuls.Latency); } CloseWindow(); }