/// <summary> /// Find OT_UNIT type of object around in-game character /// </summary> /// <param name="name"></param> /// <returns></returns> public WowUnit FindUnitByName(string name) { // Temp Update(); WowUnit res = null; foreach (WowObject wo in CurrentSnapshot.List) { if (wo.Type == Descriptor.eObjType.OT_UNIT && wo.Name.Equals(name)) { res = (WowUnit)wo; break; } } return(res); }
/// <summary> /// Convenience function that checks a buff given the name of the buff. /// </summary> /// <param name="name">Name of the buff to check.</param> public bool HasBuffByName(WowUnit unit, string BuffToCheck) { return HasBuffById(unit, GetSpellIdByName(BuffToCheck)); }
/// <summary> /// Checks if a unit has a given buff by ID /// </summary> /// <param name="unit">Unit to check for buffs</param> /// <param name="BuffToCheck">Spell ID of the buff to check</param> /// <returns>True if unit has the given buff.</returns> public bool HasBuffById(WowUnit unit, uint BuffToCheck) { uint CurrentBuff = unit.ObjectPointer + Globals.FirstBuff; uint Buff = 1; while (Buff != 0 && BuffToCheck != 0) { Buff = wow.ReadUInt(CurrentBuff); if (Buff == BuffToCheck) { return true; } CurrentBuff += Globals.NextBuff; } return false; }
public Descriptor.eUnitReaction GetUnitRelation(WowUnit u1, WowUnit u2) { if (u1 == null || u2 == null) { return Descriptor.eUnitReaction.Unknown; } if (u1.ObjectPointer == ProcessManager.Player.ObjectPointer && RelationCache.ContainsKey(u2.Guid)) { return RelationCache[u2.Guid]; } ProcessManager.SuspendMainWowThread(); uint codecave = wow.AllocateMemory(); uint result = 0; wow.Asm.Clear(); AsmUpdateCurMgr(); wow.Asm.AddLine("mov ecx, {0}", u1.ObjectPointer); wow.Asm.AddLine("push {0}", u2.ObjectPointer); wow.Asm.AddLine("call {0}", Globals.Functions.GetUnitRelation); AsmSendResumeMessage(); wow.Asm.AddLine("retn"); try { result = wow.Asm.InjectAndExecute(codecave); } catch (Exception e) { ProcessManager.ResumeMainWowThread(); throw e; } finally { wow.FreeMemory(codecave); } if (u1.ObjectPointer == ProcessManager.Player.ObjectPointer) { RelationCache.Add(u2.Guid, (Descriptor.eUnitReaction) result); } return (Descriptor.eUnitReaction) result; }
public bool Equals(WowUnit obj) { if (ReferenceEquals(null, obj)) { return false; } if (ReferenceEquals(this, obj)) { return true; } return (obj.Guid == Guid); }
public bool FindUnit(WowUnit u, string key) { DateTime start = DateTime.Now; TimeSpan tsTimeSpent; PlayerCM.SendKeys(key); Thread.Sleep(250); ulong firstGuid = CurTargetGuid; if (firstGuid == 0) { Output.Instance.Debug("We tried targeting but " + "the first TAB didn't land on anything", this); return false; } do { DateTime end = DateTime.Now; tsTimeSpent = end - start; PlayerCM.SendKeys(CommandManager.SK_TAB); Thread.Sleep(250); if (CurTargetGuid == u.Guid) { LastTargetedMob = u; Output.Instance.Debug("We found a target while TABbing", this); return true; } } while ((CurTargetGuid != u.Guid) && (CurTargetGuid != firstGuid) && (tsTimeSpent.TotalMilliseconds < 10000)); if (tsTimeSpent.TotalMilliseconds >= 10000) { // If we couldn't find the target we were looking for we clear the target ProcessManager.Injector.Lua_DoString(@"ClearTarget()"); } Output.Instance.Debug("We cycled through all the targets " + "but nothing good could be found", this); return false; }
public void AttackMobWithCTM(WowUnit mob) { if (mob == null) return; Face(mob.Location); ClickToMoveAttack(mob.Guid); }
public bool SelectWhoIsAttackingUsWithCTM() { WowUnit u = GetCurAttacker(); if (u != null) { // if we already have a target we'd better check if it's the one we want so // we avoid tabbing around uselessly if (HasTarget) { if (CurTargetGuid == u.Guid) { // we are already on the target, that's fine LastTargetedMob = u; return true; } } ClickToMoveAttack(u.Guid); } return false; }
public bool SelectUnit(WowUnit u, string key) { // We face the target otherwise the tabbing won't work as it might be out of our scope // NOTE: we are using the timed one, but it's a bit shaky //FaceUsingMemoryWrite(GetFaceAngle(u.Location), true); Face(u.Location); // We tab till we have found our target or till we come back to the first GUID we met return FindUnit(u, key); }
public bool SelectNpc(WowUnit u) { return SelectUnit(u, CommandManager.SK_CTRL_TAB); }
public bool SelectMob(WowUnit u) { return SelectUnit(u, CommandManager.SK_TAB); }
/// <summary> /// Chase a mob given its location and a distance tolerance /// </summary> /// <param name="target">Unit we want to reach</param> /// <param name="tolerance">Distance at which we can stop</param> /// <returns>A NavigationState indicating what the result of the movement was</returns> public NavigationState MoveTo(WowUnit target, float tolerance) { const CommandManager.ArrowKey key = CommandManager.ArrowKey.Up; float angle = 0; float distance = 0; int steps = 0; int currentStep = 0; float distanceFromStep = 0; //isMoving = true; if (!target.Location.IsValid()) { //isMoving = false; return NavigationState.Ready; } distance = MathFuncs.GetDistance(target.Location, Location, false); Path path = ProcessManager.Caronte.CalculatePath( new Location(Location.X, Location.Y, Location.Z), new Location(target.Location.X, target.Location.Y, target.Location.Z)); if (path == null) { Output.Instance.Debug(string.Format( "Cannot find a path from X:{0} Y:{1} Z:{2} to X:{3} Y:{4} Z:{5}", Location.X, Location.Y, Location.Z, target.Location.X, target.Location.Y, target.Location.Z), this); return NavigationState.Ready; } foreach (Location loc in path.locations) Output.Instance.Debug(string.Format( "X: {0} Y: {1} Z: {2}", loc.X, loc.Y, loc.Z), this); steps = path.locations.Count; if (steps > 0) { currentStep = 1; angle = MathFuncs.GetFaceRadian( new Vector3D(path.locations[currentStep].X, path.locations[currentStep].Y, path.locations[currentStep].Z), Location); } else { angle = MathFuncs.GetFaceRadian(target.Location, Location); } Face(angle); // Random jump int rndJmp = MathFuncs.RandomNumber(1, 8); bool doJmp = false; if (rndJmp == 1 || rndJmp == 3) doJmp = true; // Move on... PlayerCM.ArrowKeyDown(key); // Start profiler for WayPointTimeOut DateTime start = DateTime.Now; NavigationState res = NavigationState.Roaming; while (distance > tolerance) { float currentDistance = distance; if (doJmp) { doJmp = false; PlayerCM.SendKeys(" "); } if (StopMovement) { res = NavigationState.Ready; StopMovement = false; break; } distance = MathFuncs.GetDistance(target.Location, Location, false); if (steps > 0) { distanceFromStep = MathFuncs.GetDistance( new Vector3D(path.locations[currentStep].X, path.locations[currentStep].Y, path.locations[currentStep].Z), Location, false); Output.Instance.Debug("Step: " + currentStep, this); Output.Instance.Debug("Location: " + Location, this); Output.Instance.Debug("Distance from step: " + distanceFromStep, this); Output.Instance.Debug("Distance from target: " + distance, this); if (distanceFromStep < 10.0f) { if (currentStep < steps - 1) { currentStep++; if ((steps > 0) && (currentStep < steps - 1)) { angle = MathFuncs.GetFaceRadian(new Vector3D(path.locations[currentStep].X, path.locations[currentStep].Y, path.locations[currentStep].Z), Location); } else { angle = MathFuncs.GetFaceRadian(target.Location, Location); } // NOTE: tanis - I've switched this to the memory write one. // I dunno if it's better yet //Face(angle); angle = MathFuncs.GetFaceRadian( WaypointVector3DHelper.LocationToVector3D( path.locations[currentStep]),Location); FaceUsingMemoryWrite(angle, true); // NOTE: tanis - end } } } Thread.Sleep(50); Application.DoEvents(); DateTime end = DateTime.Now; TimeSpan tsTravelTime = end - start; TravelTime = tsTravelTime.Milliseconds + tsTravelTime.Seconds*1000; if (currentDistance == distance) { /// We should come up with a routine to get us unstuck. /// Of course we should also add some tolerance here as it is unlikely that /// we will be exactly in the same position when we get stuck } else if (TravelTime >= MAX_REACHTIME) { TravelTime = 0; res = NavigationState.WayPointTimeout; break; } Output.Instance.Debug(string.Format( "Tolerance: {0} - Distance: {1}", tolerance, distance), this); } PlayerCM.ArrowKeyUp(key); //isMoving = false; return res; }
/// <summary> /// Loots a mob and remove it from the lootable list. We must already be near the corpse /// </summary> /// <param name="mob">Corpse that we want to loot</param> public void Loot(WowUnit mob) { Output.Instance.Debug("Loot() - Interacting with the corpse mob", this); //mob.Interact(); ProcessManager.Injector.Lua_DoString(@"InteractUnit(""target"")"); Thread.Sleep(2000); Output.Instance.Debug("Loot() - Removing this corpse from the list", this); LootableList.Remove(mob); }
public bool IsInMobBlackList(WowUnit mob) { foreach (var ent in MobBlackList) { if (ent.Guid == mob.Guid) return true; } return false; }